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

Add Replace in Files command to Edit main-menu #10242

Merged
merged 1 commit into from
Oct 26, 2021
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 @@ -41,6 +41,11 @@ export namespace SearchInWorkspaceCommands {
category: SEARCH_CATEGORY,
label: 'Find in Files'
}, 'vscode/search.contribution/findInFiles', SEARCH_CATEGORY_KEY);
export const REPLACE_IN_FILES = Command.toLocalizedCommand({
id: 'search-in-workspace.replace',
category: SEARCH_CATEGORY,
label: 'Replace in Files'
}, 'vscode/searchActions/replaceInFiles', SEARCH_CATEGORY_KEY);
export const FIND_IN_FOLDER = Command.toLocalizedCommand({
id: 'search-in-workspace.in-folder',
category: SEARCH_CATEGORY,
Expand Down Expand Up @@ -125,6 +130,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 @@ -214,7 +227,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 @@ -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();
}

Expand Down