From c473b6bf15981db886157e1c934ea24400d078be Mon Sep 17 00:00:00 2001 From: smart-bo Date: Wed, 6 Oct 2021 14:45:27 -0400 Subject: [PATCH] Add 'replace in files' command --- ...arch-in-workspace-frontend-contribution.ts | 25 ++++++++++++++++++- .../browser/search-in-workspace-widget.tsx | 6 ++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts b/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts index f7d249cd52f54..cdb01898e7a57 100644 --- a/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts +++ b/packages/search-in-workspace/src/browser/search-in-workspace-frontend-contribution.ts @@ -40,8 +40,18 @@ export namespace SearchInWorkspaceCommands { id: 'search-in-workspace.open', category: SEARCH_CATEGORY, label: 'Find in Files' +<<<<<<< HEAD }, 'vscode/search.contribution/findInFiles', SEARCH_CATEGORY_KEY); export const FIND_IN_FOLDER = Command.toLocalizedCommand({ +======= + }; + export const REPLACE_IN_FILES: Command = { + id: 'search-in-workspace.replace', + category: SEARCH_CATEGORY, + label: 'Replace in Files' + }; + export const FIND_IN_FOLDER: Command = { +>>>>>>> beac550c251 (Add 'replace in files' command) id: 'search-in-workspace.in-folder', category: SEARCH_CATEGORY, label: 'Find in Folder' @@ -125,6 +135,14 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut } }); + commands.registerCommand(SearchInWorkspaceCommands.REPLACE_IN_FILES, { + isEnabled: () => this.workspaceService.tryGetRoots().length > 0, + execute: async () => { + const widget = await this.openView({ activate: true }); + widget.updateSearchTerm(this.getSearchTerm(), true); + } + }); + commands.registerCommand(SearchInWorkspaceCommands.FIND_IN_FOLDER, this.newMultiUriAwareCommandHandler({ execute: async uris => { const resources: string[] = []; @@ -214,7 +232,12 @@ export class SearchInWorkspaceFrontendContribution extends AbstractViewContribut commandId: SearchInWorkspaceCommands.FIND_IN_FOLDER.id }); menus.registerMenuAction(CommonMenus.EDIT_FIND, { - commandId: SearchInWorkspaceCommands.OPEN_SIW_WIDGET.id + commandId: SearchInWorkspaceCommands.OPEN_SIW_WIDGET.id, + order: '2' + }); + menus.registerMenuAction(CommonMenus.EDIT_FIND, { + commandId: SearchInWorkspaceCommands.REPLACE_IN_FILES.id, + order: '3' }); } diff --git a/packages/search-in-workspace/src/browser/search-in-workspace-widget.tsx b/packages/search-in-workspace/src/browser/search-in-workspace-widget.tsx index 719ac4337284d..e8930c482c4ee 100644 --- a/packages/search-in-workspace/src/browser/search-in-workspace-widget.tsx +++ b/packages/search-in-workspace/src/browser/search-in-workspace-widget.tsx @@ -230,13 +230,17 @@ export class SearchInWorkspaceWidget extends BaseWidget implements StatefulWidge /** * Update the search term and input field. * @param term the search term. + * @param showReplaceField controls if the replace field should be displayed. */ - updateSearchTerm(term: string): void { + updateSearchTerm(term: string, showReplaceField?: boolean): void { this.searchTerm = term; const search = document.getElementById('search-input-field'); if (search) { (search as HTMLInputElement).value = term; } + if (showReplaceField) { + this.showReplaceField = true; + } this.refresh(); }