Skip to content

Commit 4e5fc28

Browse files
authored
refactor: replace DeprecatedRecycleTree on Search view (#2102)
* refactor: replace DeprecatedRecycleTree on Search view * feat: support inline actions * feat: support contextmenu * chore: update search contextkey * test: add search service test * chore: fix node test * chore: fix focus * chore: fixe typo
1 parent 0f7204f commit 4e5fc28

32 files changed

Lines changed: 2170 additions & 1478 deletions

packages/components/src/recycle-tree/types/watcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export interface ITreeWatcher {
110110
// 监听watcheEvent事件,如节点移动,新建,删除
111111
onWatchEvent(path: string, callback: IWatcherCallback): IWatchTerminator;
112112
// 监听所有事件
113-
on(event: TreeNodeEvent, callback: any);
113+
on(event: TreeNodeEvent, callback: any): IDisposable;
114114

115115
// 事件分发
116116

packages/core-browser/src/common/common.command.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,13 +681,6 @@ export namespace SEARCH_COMMANDS {
681681
category: CATEGORY,
682682
};
683683

684-
export const FOLD: Command = {
685-
id: 'file-search.fold',
686-
label: 'fold search',
687-
iconClass: getIcon('collapse-all'),
688-
category: CATEGORY,
689-
};
690-
691684
export const GET_RECENT_SEARCH_WORD: Command = {
692685
id: 'search.getRecentSearchWordCmd',
693686
category: CATEGORY,
@@ -733,6 +726,16 @@ export namespace SEARCH_COMMANDS {
733726
category: CATEGORY,
734727
label: '%file.copy.path%',
735728
};
729+
730+
export const REPLACE: Command = {
731+
id: 'search.replace',
732+
category: CATEGORY,
733+
};
734+
735+
export const CLOSE: Command = {
736+
id: 'search.close',
737+
category: CATEGORY,
738+
};
736739
}
737740

738741
export namespace OUTLINE_COMMANDS {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { RawContextKey } from '../raw-context-key';
2+
3+
// https://github.com/microsoft/vscode/blob/9318bcc5183dbbc49cea8843859cbdeb59b94eaf/src/vs/workbench/contrib/search/common/constants.ts
4+
export const SearchViewFocusedKey = new RawContextKey<boolean>('searchViewletFocus', false);
5+
export const SearchInputBoxFocusedKey = new RawContextKey<boolean>('searchInputBoxFocus', false);
6+
export const ReplaceInputBoxFocusedKey = new RawContextKey<boolean>('replaceInputBoxFocus', false);
7+
export const HasSearchResults = new RawContextKey<boolean>('hasSearchResult', false);
8+
9+
// not impliments
10+
export const SearchViewVisibleKey = new RawContextKey<boolean>('searchViewletVisible', true);
11+
export const InputBoxFocusedKey = new RawContextKey<boolean>('inputBoxFocus', false);
12+
export const PatternIncludesFocusedKey = new RawContextKey<boolean>('patternIncludesInputBoxFocus', false);
13+
export const PatternExcludesFocusedKey = new RawContextKey<boolean>('patternExcludesInputBoxFocus', false);
14+
export const ReplaceActiveKey = new RawContextKey<boolean>('replaceActive', false);
15+
export const FirstMatchFocusKey = new RawContextKey<boolean>('firstMatchFocus', false);
16+
export const FileMatchOrMatchFocusKey = new RawContextKey<boolean>('fileMatchOrMatchFocus', false); // This is actually, Match or File or Folder
17+
export const FileMatchOrFolderMatchFocusKey = new RawContextKey<boolean>('fileMatchOrFolderMatchFocus', false);
18+
export const FileMatchOrFolderMatchWithResourceFocusKey = new RawContextKey<boolean>(
19+
'fileMatchOrFolderMatchWithResourceFocus',
20+
false,
21+
); // Excludes "Other files"
22+
export const FileFocusKey = new RawContextKey<boolean>('fileMatchFocus', false);
23+
export const FolderFocusKey = new RawContextKey<boolean>('folderMatchFocus', false);
24+
export const ResourceFolderFocusKey = new RawContextKey<boolean>('folderMatchWithResourceFocus', false);
25+
export const MatchFocusKey = new RawContextKey<boolean>('matchFocus', false);
26+
export const ViewHasSearchPatternKey = new RawContextKey<boolean>('viewHasSearchPattern', false);
27+
export const ViewHasReplacePatternKey = new RawContextKey<boolean>('viewHasReplacePattern', false);
28+
export const ViewHasFilePatternKey = new RawContextKey<boolean>('viewHasFilePattern', false);
29+
export const ViewHasSomeCollapsibleKey = new RawContextKey<boolean>('viewHasSomeCollapsibleResult', false);
30+
export const InTreeViewKey = new RawContextKey<boolean>('inTreeView', false);

packages/debug/src/browser/view/console/debug-console-tree.model.service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,21 @@ export class DebugConsoleModelService {
235235

236236
listenTreeViewChange() {
237237
this.disposeTreeModel();
238+
if (!this.treeModel) {
239+
return;
240+
}
238241
this.treeModelDisposableCollection.push(
239-
this.treeModel?.root.watcher.on(TreeNodeEvent.WillResolveChildren, (target) => {
242+
this.treeModel.root.watcher.on(TreeNodeEvent.WillResolveChildren, (target) => {
240243
this.loadingDecoration.addTarget(target);
241244
}),
242245
);
243246
this.treeModelDisposableCollection.push(
244-
this.treeModel?.root.watcher.on(TreeNodeEvent.DidResolveChildren, (target) => {
247+
this.treeModel.root.watcher.on(TreeNodeEvent.DidResolveChildren, (target) => {
245248
this.loadingDecoration.removeTarget(target);
246249
}),
247250
);
248251
this.treeModelDisposableCollection.push(
249-
this.treeModel!.onWillUpdate(() => {
252+
this.treeModel.onWillUpdate(() => {
250253
// 更新树前更新下选中节点
251254
if (this.selectedNodes.length !== 0) {
252255
// 仅处理一下单选情况

packages/debug/src/browser/view/variables/debug-variables-tree.model.service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,21 @@ export class DebugVariablesModelService {
239239

240240
listenTreeViewChange() {
241241
this.dispose();
242+
if (!this.treeModel) {
243+
return;
244+
}
242245
this.disposableCollection.push(
243-
this.treeModel?.root.watcher.on(TreeNodeEvent.WillResolveChildren, (target) => {
246+
this.treeModel.root.watcher.on(TreeNodeEvent.WillResolveChildren, (target) => {
244247
this.loadingDecoration.addTarget(target);
245248
}),
246249
);
247250
this.disposableCollection.push(
248-
this.treeModel?.root.watcher.on(TreeNodeEvent.DidResolveChildren, (target) => {
251+
this.treeModel.root.watcher.on(TreeNodeEvent.DidResolveChildren, (target) => {
249252
this.loadingDecoration.removeTarget(target);
250253
}),
251254
);
252255
this.disposableCollection.push(
253-
this.treeModel!.onWillUpdate(() => {
256+
this.treeModel.onWillUpdate(() => {
254257
// 更新树前更新下选中节点
255258
if (this.selectedNodes.length !== 0) {
256259
// 仅处理一下单选情况

packages/debug/src/browser/view/watch/debug-watch-tree.model.service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,21 @@ export class DebugWatchModelService {
212212

213213
listenTreeViewChange() {
214214
this.dispose();
215+
if (!this.treeModel) {
216+
return;
217+
}
215218
this.disposableCollection.push(
216-
this.treeModel?.root.watcher.on(TreeNodeEvent.WillResolveChildren, (target) => {
219+
this.treeModel.root.watcher.on(TreeNodeEvent.WillResolveChildren, (target) => {
217220
this.loadingDecoration.addTarget(target);
218221
}),
219222
);
220223
this.disposableCollection.push(
221-
this.treeModel?.root.watcher.on(TreeNodeEvent.DidResolveChildren, (target) => {
224+
this.treeModel.root.watcher.on(TreeNodeEvent.DidResolveChildren, (target) => {
222225
this.loadingDecoration.removeTarget(target);
223226
}),
224227
);
225228
this.disposableCollection.push(
226-
this.treeModel!.onWillUpdate(() => {
229+
this.treeModel.onWillUpdate(() => {
227230
// 更新树前更新下选中节点
228231
if (this.selectedNodes.length !== 0) {
229232
// 仅处理一下单选情况

packages/file-tree-next/src/browser/file-tree.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,16 @@ export const FileTree = ({ viewState }: PropsWithChildren<{ viewState: ViewState
116116
[],
117117
);
118118

119-
const handleItemDoubleClicked = useCallback(
120-
(event: MouseEvent, item: File | Directory, type: TreeNodeType, activeUri?: URI) => {
121-
// 阻止点击事件冒泡
122-
event.stopPropagation();
119+
const handleItemDoubleClicked = useCallback((event: MouseEvent, item: File | Directory, type: TreeNodeType) => {
120+
// 阻止点击事件冒泡
121+
event.stopPropagation();
123122

124-
const { handleItemDoubleClick } = fileTreeModelService;
125-
if (!item) {
126-
return;
127-
}
128-
handleItemDoubleClick(item, type, activeUri);
129-
},
130-
[],
131-
);
123+
const { handleItemDoubleClick } = fileTreeModelService;
124+
if (!item) {
125+
return;
126+
}
127+
handleItemDoubleClick(item, type);
128+
}, []);
132129

133130
const handleTwistierClick = useCallback((ev: MouseEvent, item: Directory) => {
134131
// 阻止点击事件冒泡

packages/file-tree-next/src/browser/services/file-tree-model.service.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ import {
3030
Emitter,
3131
Deferred,
3232
CommandService,
33-
IApplicationService,
3433
FILE_COMMANDS,
3534
path,
3635
IClipboardService,
37-
AppConfig,
3836
} from '@opensumi/ide-core-browser';
3937
import { ResourceContextKey } from '@opensumi/ide-core-browser/lib/contextkey/resource';
4038
import { AbstractContextMenuService, MenuId, ICtxMenuRenderer } from '@opensumi/ide-core-browser/lib/menu/next';
@@ -860,7 +858,7 @@ export class FileTreeModelService {
860858
}
861859
};
862860

863-
handleItemDoubleClick = (item: File | Directory, type: TreeNodeType, activeUri?: URI) => {
861+
handleItemDoubleClick = (item: File | Directory, type: TreeNodeType) => {
864862
// 双击事件触发前,会先触发 handleItemClick 方法装饰文件
865863
if (type === TreeNodeType.TreeNode) {
866864
// 双击的时候,不管 workbench.list.openMode 为单击还是双击,都以非预览模式打开文件

packages/i18n/src/common/en-US.lang.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export const localizationBundle = {
209209
'search.includes.description': 'Enter the file name or folder name, multiple separated by ","',
210210
'search.excludes': 'Files to exclude',
211211
'search.excludes.default.enable': 'Enable default exclusions',
212-
'search.replaceAll.label': 'Replace all',
212+
'search.replaceAll.label': 'Replace All',
213213
'search.replace.label': 'Replace',
214214
'search.files.result': '{0} results found in {1} files',
215215
'search.CollapseDeepestExpandedLevelAction.label': 'Collapse All',
@@ -219,7 +219,7 @@ export const localizationBundle = {
219219
'search.removeAll.occurrences.files.confirmation.message': 'Are you sure to replace {0} of the {1} files',
220220
'search.removeAll.occurrences.file.confirmation.message': 'Are you sure to replace the {0} results in this file?',
221221
'search.result.hide': 'Hide',
222-
'search.menu.copyAll': 'Copy all',
222+
'search.menu.copyAll': 'Copy All',
223223
'search.help.showIncludeRule': 'View syntax rules',
224224
'search.help.supportRule': 'Support the following syntax rules:',
225225
'search.help.excludeList': 'Excluded items include:',

packages/outline/src/browser/services/outline-model.service.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ export class OutlineModelService {
9393
// 选中态的节点
9494
private _selectedNodes: (OutlineCompositeTreeNode | OutlineTreeNode)[] = [];
9595

96-
private preContextMenuFocusedNode: OutlineCompositeTreeNode | OutlineTreeNode | null;
97-
9896
private disposableCollection: DisposableCollection = new DisposableCollection();
9997

10098
private onDidRefreshedEmitter: Emitter<void> = new Emitter();
@@ -354,11 +352,6 @@ export class OutlineModelService {
354352

355353
// 清空其他选中/焦点态节点,更新当前焦点节点
356354
activeNodeDecoration = (target: OutlineCompositeTreeNode | OutlineTreeNode, dispatch = true) => {
357-
if (this.preContextMenuFocusedNode) {
358-
this.focusedDecoration.removeTarget(this.preContextMenuFocusedNode);
359-
this.selectedDecoration.removeTarget(this.preContextMenuFocusedNode);
360-
this.preContextMenuFocusedNode = null;
361-
}
362355
if (target) {
363356
for (const target of this.selectedDecoration.appliedTargets.keys()) {
364357
this.selectedDecoration.removeTarget(target);
@@ -378,9 +371,6 @@ export class OutlineModelService {
378371

379372
// 清空其他选中/焦点态节点,更新当前选中节点
380373
selectNodeDecoration = (target: OutlineCompositeTreeNode | OutlineTreeNode, dispatch = true) => {
381-
if (this.preContextMenuFocusedNode) {
382-
this.focusedDecoration.removeTarget(this.preContextMenuFocusedNode);
383-
}
384374
if (target) {
385375
if (this.selectedNodes.length > 0) {
386376
this.selectedNodes.forEach((node) => {
@@ -407,16 +397,11 @@ export class OutlineModelService {
407397
if (this.focusedNode !== target) {
408398
if (removePreFocusedDecoration) {
409399
// 当存在上一次右键菜单激活的文件时,需要把焦点态的文件节点的装饰器全部移除
410-
if (this.preContextMenuFocusedNode) {
411-
this.focusedDecoration.removeTarget(this.preContextMenuFocusedNode);
412-
this.selectedDecoration.removeTarget(this.preContextMenuFocusedNode);
413-
} else if (this.focusedNode) {
400+
if (this.focusedNode) {
414401
// 多选情况下第一次切换焦点文件
415402
this.focusedDecoration.removeTarget(this.focusedNode);
416403
}
417-
this.preContextMenuFocusedNode = target;
418404
} else if (this.focusedNode) {
419-
this.preContextMenuFocusedNode = null;
420405
this.focusedDecoration.removeTarget(this.focusedNode);
421406
}
422407
if (target) {

0 commit comments

Comments
 (0)