Skip to content

Commit

Permalink
searchInWorkspace: Implement Multiselect
Browse files Browse the repository at this point in the history
Closes #11874

Implements in Search-In-Workspace:
- Multiselect search results.
- `delete` keybinding dismiss selected results.
- `Ctrl`+`C` keybinding to copy selected results.
- Handling for action buttons: `Replace` and `Dismiss`

`enter` in replace-inputbox refreshes search results,
instead of on every key.

Signed-Off-By: FernandoAscencio <fernando.ascencio.cama@ericsson.com>
  • Loading branch information
FernandoAscencio committed Apr 4, 2023
1 parent 25af1d9 commit 05cd46c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
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 } 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 Down Expand Up @@ -218,7 +218,9 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut
execute: () => this.withWidget(undefined, widget => {
const { selection } = this.selectionService;
if (TreeWidgetSelection.is(selection)) {
widget.resultTreeWidget.removeNode(selection[0]);
for (const selected of selection) {
widget.resultTreeWidget.removeNode(selected);
}
}
})
});
Expand Down Expand Up @@ -303,6 +305,16 @@ 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.COPY_ONE.id,
keybinding: 'ctrlcmd+c',
when: 'searchViewletFocus && !inputBoxFocus'
});
}

override registerMenus(menus: MenuModelRegistry): void {
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 @@ -52,6 +52,7 @@ import * as minimatch from 'minimatch';
import { DisposableCollection } from '@theia/core/lib/common/disposable';
import debounce = require('@theia/core/shared/lodash.debounce');
import { nls } from '@theia/core/lib/common/nls';
import { TreeWidgetSelection } from '@theia/core/lib/browser/tree/tree-widget-selection';

const ROOT_ID = 'ResultTree';

Expand Down Expand Up @@ -737,7 +738,10 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget {
}

protected doReplace(node: TreeNode, e: React.MouseEvent<HTMLElement>): void {
this.replace(node);
const { selection } = this.selectionService;
if (TreeWidgetSelection.is(selection) && SelectableTreeNode.isSelected(node)) {
selection.forEach(n => { if (TreeNode.is(n)) { this.replace(n); } });
} else { this.replace(node); }
e.stopPropagation();
}

Expand Down Expand Up @@ -899,7 +903,10 @@ 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 } = this.selectionService;
if (TreeWidgetSelection.is(selection) && SelectableTreeNode.isSelected(node)) {
selection.forEach(n => { if (TreeNode.is(n)) { this.removeNode(n); } });
} else { this.removeNode(node); }
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

0 comments on commit 05cd46c

Please sign in to comment.