Skip to content

Commit

Permalink
Add 'replace in files' command
Browse files Browse the repository at this point in the history
  • Loading branch information
smart-bo committed Oct 12, 2021
1 parent 9e5b1ca commit e5de644
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export namespace SearchInWorkspaceCommands {
id: 'search-in-workspace.open',
category: SEARCH_CATEGORY,
label: 'Find in Files'

};
export const REPLACE_IN_FILES: Command = {
id: 'search-in-workspace.replace',
category: SEARCH_CATEGORY,
label: 'Replace in Files'
};
export const FIND_IN_FOLDER: Command = {
id: 'search-in-workspace.in-folder',
Expand Down Expand Up @@ -123,6 +127,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[] = [];
Expand Down Expand Up @@ -212,7 +224,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'
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,17 @@ export class SearchInWorkspaceWidget extends BaseWidget implements StatefulWidge
* Update the search term and input field.
* @param term the search term.
*/
updateSearchTerm(term: string): void {
this.searchTerm = term;
updateSearchTerm(searchTerm: string, replaceTerm?: boolean): void {
this.searchTerm = searchTerm;
const search = document.getElementById('search-input-field');
if (search) {
(search as HTMLInputElement).value = term;
(search as HTMLInputElement).value = searchTerm;
}
this.refresh();
if (replaceTerm) {
this.showReplaceField = true;
this.resultTreeWidget.showReplaceButtons = this.showReplaceField;
}
this.update();
}

hasResultList(): boolean {
Expand Down

0 comments on commit e5de644

Please sign in to comment.