Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search-In-Workspace: Add multiselect functionality #12331

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@theia/core/lib/browser';
import { SearchInWorkspaceWidget } from './search-in-workspace-widget';
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
import { CommandRegistry, MenuModelRegistry, SelectionService, Command } from '@theia/core';
import { CommandRegistry, MenuModelRegistry, SelectionService, Command, isOSX, nls } from '@theia/core';
import { codicon, Widget } from '@theia/core/lib/browser/widgets';
import { FileNavigatorCommands, NavigatorContextMenu } from '@theia/navigator/lib/browser/navigator-contribution';
import { UriCommandHandler, UriAwareCommandHandler } from '@theia/core/lib/common/uri-command-handler';
Expand All @@ -32,7 +32,7 @@ import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
import { Range } from '@theia/core/shared/vscode-languageserver-protocol';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { SEARCH_VIEW_CONTAINER_ID } from './search-in-workspace-factory';
import { SearchInWorkspaceResultTreeWidget } from './search-in-workspace-result-tree-widget';
import { SearchInWorkspaceFileNode, SearchInWorkspaceResultTreeWidget } from './search-in-workspace-result-tree-widget';
import { TreeWidgetSelection } from '@theia/core/lib/browser/tree/tree-widget-selection';
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
import { isHighContrast } from '@theia/core/lib/common/theme';
Expand Down Expand Up @@ -102,6 +102,12 @@ export namespace SearchInWorkspaceCommands {
category: SEARCH_CATEGORY,
label: 'Dismiss',
});
export const REPLACE_RESULT = Command.toDefaultLocalizedCommand({
id: 'search.action.replace',
});
export const REPLACE_ALL_RESULTS = Command.toDefaultLocalizedCommand({
id: 'search.action.replaceAll'
});
}

@injectable()
Expand Down Expand Up @@ -218,10 +224,44 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut
execute: () => this.withWidget(undefined, widget => {
const { selection } = this.selectionService;
if (TreeWidgetSelection.is(selection)) {
widget.resultTreeWidget.removeNode(selection[0]);
selection.forEach(n => widget.resultTreeWidget.removeNode(n));
}
})
});
commands.registerCommand(SearchInWorkspaceCommands.REPLACE_RESULT, {
isEnabled: () => this.withWidget(undefined, widget => {
const { selection } = this.selectionService;
return TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0 && !SearchInWorkspaceFileNode.is(selection[0]);
}),
isVisible: () => this.withWidget(undefined, widget => {
const { selection } = this.selectionService;
return TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0 && !SearchInWorkspaceFileNode.is(selection[0]);
}),
execute: () => this.withWidget(undefined, widget => {
const { selection } = this.selectionService;
if (TreeWidgetSelection.is(selection)) {
selection.forEach(n => widget.resultTreeWidget.replace(n));
}
}),
});
commands.registerCommand(SearchInWorkspaceCommands.REPLACE_ALL_RESULTS, {
isEnabled: () => this.withWidget(undefined, widget => {
const { selection } = this.selectionService;
return TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0
&& SearchInWorkspaceFileNode.is(selection[0]);
}),
isVisible: () => this.withWidget(undefined, widget => {
const { selection } = this.selectionService;
return TreeWidgetSelection.isSource(selection, widget.resultTreeWidget) && selection.length > 0
&& SearchInWorkspaceFileNode.is(selection[0]);
}),
execute: () => this.withWidget(undefined, widget => {
const { selection } = this.selectionService;
if (TreeWidgetSelection.is(selection)) {
selection.forEach(n => widget.resultTreeWidget.replace(n));
}
}),
});
commands.registerCommand(SearchInWorkspaceCommands.COPY_ONE, {
isEnabled: () => this.withWidget(undefined, widget => {
const { selection } = this.selectionService;
Expand Down Expand Up @@ -303,6 +343,26 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut
keybinding: 'shift+alt+f',
when: 'explorerResourceIsFolder'
});
keybindings.registerKeybinding({
command: SearchInWorkspaceCommands.DISMISS_RESULT.id,
keybinding: isOSX ? 'cmd+backspace' : 'del',
when: 'searchViewletFocus && !inputBoxFocus'
});
keybindings.registerKeybinding({
command: SearchInWorkspaceCommands.REPLACE_RESULT.id,
keybinding: 'ctrlcmd+shift+1',
when: 'searchViewletFocus && replaceActive',
});
keybindings.registerKeybinding({
command: SearchInWorkspaceCommands.REPLACE_ALL_RESULTS.id,
keybinding: 'ctrlcmd+shift+1',
when: 'searchViewletFocus && replaceActive',
});
keybindings.registerKeybinding({
command: SearchInWorkspaceCommands.COPY_ONE.id,
keybinding: 'ctrlcmd+c',
when: 'searchViewletFocus && !inputBoxFocus'
});
}

override registerMenus(menus: MenuModelRegistry): void {
Expand All @@ -319,6 +379,18 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut
commandId: SearchInWorkspaceCommands.REPLACE_IN_FILES.id,
order: '3'
});
menus.registerMenuAction(SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, {
commandId: SearchInWorkspaceCommands.REPLACE_RESULT.id,
label: nls.localizeByDefault('Replace'),
order: '1',
when: 'replaceActive',
});
menus.registerMenuAction(SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, {
commandId: SearchInWorkspaceCommands.REPLACE_ALL_RESULTS.id,
label: nls.localizeByDefault('Replace All'),
order: '1',
when: 'replaceActive',
});
menus.registerMenuAction(SearchInWorkspaceResultTreeWidget.Menus.INTERNAL, {
commandId: SearchInWorkspaceCommands.DISMISS_RESULT.id,
order: '1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export function createSearchTreeWidget(parent: interfaces.Container): SearchInWo
widget: SearchInWorkspaceResultTreeWidget,
props: {
contextMenuPath: SearchInWorkspaceResultTreeWidget.Menus.BASE,
multiSelect: true,
globalSelection: true
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,8 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {
}

protected doReplace(node: TreeNode, e: React.MouseEvent<HTMLElement>): void {
this.replace(node);
const selection = SelectableTreeNode.isSelected(node) ? (this.selectionService.selection as SelectableTreeNode[]) : [node];
selection.forEach(n => this.replace(n));
e.stopPropagation();
}

Expand Down Expand Up @@ -899,7 +900,8 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {

protected readonly remove = (node: TreeNode, e: React.MouseEvent<HTMLElement>) => this.doRemove(node, e);
protected doRemove(node: TreeNode, e: React.MouseEvent<HTMLElement>): void {
this.removeNode(node);
const selection = SelectableTreeNode.isSelected(node) ? (this.selectionService.selection as SelectableTreeNode[]) : [node];
selection.forEach(n => this.removeNode(n));
e.stopPropagation();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export class SearchInWorkspaceWidget extends BaseWidget implements StatefulWidge
if (e.target) {
this.replaceTerm = (e.target as HTMLInputElement).value;
this.resultTreeWidget.replaceTerm = this.replaceTerm;
this.performSearch();
if (KeyCode.createKeyCode(e.nativeEvent).key?.keyCode === Key.ENTER.keyCode) { this.performSearch(); }
this.update();
}
}
Expand Down