Skip to content

FindInFiles converted to command and accepting arguments #71626

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

Merged
merged 3 commits into from
Apr 8, 2019
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
11 changes: 9 additions & 2 deletions src/vs/workbench/contrib/search/browser/search.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { ExplorerFolderContext, ExplorerRootContext, FilesExplorerFocusCondition
import { OpenAnythingHandler } from 'vs/workbench/contrib/search/browser/openAnythingHandler';
import { OpenSymbolHandler } from 'vs/workbench/contrib/search/browser/openSymbolHandler';
import { registerContributions as replaceContributions } from 'vs/workbench/contrib/search/browser/replaceContributions';
import { clearHistoryCommand, ClearSearchResultsAction, CloseReplaceAction, CollapseDeepestExpandedLevelAction, copyAllCommand, copyMatchCommand, copyPathCommand, FindInFilesAction, FocusNextInputAction, FocusNextSearchResultAction, FocusPreviousInputAction, FocusPreviousSearchResultAction, focusSearchListCommand, getSearchView, openSearchView, OpenSearchViewletAction, RefreshAction, RemoveAction, ReplaceAction, ReplaceAllAction, ReplaceAllInFolderAction, ReplaceInFilesAction, toggleCaseSensitiveCommand, toggleRegexCommand, toggleWholeWordCommand } from 'vs/workbench/contrib/search/browser/searchActions';
import { clearHistoryCommand, ClearSearchResultsAction, CloseReplaceAction, CollapseDeepestExpandedLevelAction, copyAllCommand, copyMatchCommand, copyPathCommand, FocusNextInputAction, FocusNextSearchResultAction, FocusPreviousInputAction, FocusPreviousSearchResultAction, focusSearchListCommand, getSearchView, openSearchView, OpenSearchViewletAction, RefreshAction, RemoveAction, ReplaceAction, ReplaceAllAction, ReplaceAllInFolderAction, ReplaceInFilesAction, toggleCaseSensitiveCommand, toggleRegexCommand, toggleWholeWordCommand, FindInFilesCommand } from 'vs/workbench/contrib/search/browser/searchActions';
import { SearchPanel } from 'vs/workbench/contrib/search/browser/searchPanel';
import { SearchView } from 'vs/workbench/contrib/search/browser/searchView';
import { SearchViewlet } from 'vs/workbench/contrib/search/browser/searchViewlet';
Expand Down Expand Up @@ -525,7 +525,14 @@ const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.Workbenc
// Show Search and Find in Files are redundant, but we can't break keybindings by removing one. So it's the same action, same keybinding, registered to different IDs.
// Show Search 'when' is redundant but if the two conflict with exactly the same keybinding and 'when' clause, then they can show up as "unbound" - #51780
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenSearchViewletAction, VIEWLET_ID, OpenSearchViewletAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F }, Constants.SearchViewVisibleKey.toNegated()), 'View: Show Search', nls.localize('view', "View"));
registry.registerWorkbenchAction(new SyncActionDescriptor(FindInFilesAction, Constants.FindInFilesActionId, nls.localize('findInFiles', "Find in Files"), { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F }), 'Find in Files', category);
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: Constants.FindInFilesActionId,
weight: KeybindingWeight.WorkbenchContrib,
when: null,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F,
handler: FindInFilesCommand
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: Constants.FindInFilesActionId, title: { value: nls.localize('findInFiles', "Find in Files"), original: 'Find in Files' }, category } });
MenuRegistry.appendMenuItem(MenuId.MenubarEditMenu, {
group: '4_find_global',
command: {
Expand Down
40 changes: 28 additions & 12 deletions src/vs/workbench/contrib/search/browser/searchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,35 @@ export abstract class FindOrReplaceInFilesAction extends Action {
});
}
}

export class FindInFilesAction extends FindOrReplaceInFilesAction {

static readonly LABEL = nls.localize('findInFiles', "Find in Files");

constructor(id: string, label: string,
@IViewletService viewletService: IViewletService,
@IPanelService panelService: IPanelService,
@IConfigurationService configurationService: IConfigurationService
) {
super(id, label, viewletService, panelService, configurationService, /*expandSearchReplaceWidget=*/false);
}
export interface IFindInFilesArgs {
query?: string;
replace?: string;
triggerSearch?: boolean;
filesToInclude?: string;
filesToExclude?: string;
isRegex?: boolean;
isCaseSensitive?: boolean;
matchWholeWord?: boolean;
}
export const FindInFilesCommand: ICommandHandler = (accessor, args: IFindInFilesArgs = {}) => {

const viewletService = accessor.get(IViewletService);
const panelService = accessor.get(IPanelService);
const configurationService = accessor.get(IConfigurationService);
openSearchView(viewletService, panelService, configurationService, false).then(openedView => {
if (openedView) {
const searchAndReplaceWidget = openedView.searchAndReplaceWidget;
searchAndReplaceWidget.toggleReplace(typeof args.replace === 'string');
let updatedText = false;
if (typeof args.query === 'string') {
openedView.setSearchParameters(args);
} else {
updatedText = openedView.updateTextFromSelection((typeof args.replace !== 'string'));
}
openedView.searchAndReplaceWidget.focus(undefined, updatedText, updatedText);
}
});
};

export class OpenSearchViewletAction extends FindOrReplaceInFilesAction {

Expand Down
33 changes: 32 additions & 1 deletion src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { OpenFileFolderAction, OpenFolderAction } from 'vs/workbench/browser/act
import { ResourceLabels, IResourceLabelsContainer } from 'vs/workbench/browser/labels';
import { IEditor } from 'vs/workbench/common/editor';
import { ExcludePatternInputWidget, PatternInputWidget } from 'vs/workbench/contrib/search/browser/patternInputWidget';
import { CancelSearchAction, ClearSearchResultsAction, CollapseDeepestExpandedLevelAction, RefreshAction } from 'vs/workbench/contrib/search/browser/searchActions';
import { CancelSearchAction, ClearSearchResultsAction, CollapseDeepestExpandedLevelAction, RefreshAction, IFindInFilesArgs } from 'vs/workbench/contrib/search/browser/searchActions';
import { FileMatchRenderer, FolderMatchRenderer, MatchRenderer, SearchAccessibilityProvider, SearchDelegate, SearchDND } from 'vs/workbench/contrib/search/browser/searchResultsView';
import { ISearchWidgetOptions, SearchWidget } from 'vs/workbench/contrib/search/browser/searchWidget';
import * as Constants from 'vs/workbench/contrib/search/common/constants';
Expand Down Expand Up @@ -1043,6 +1043,37 @@ export class SearchView extends ViewletPanel {
this.onQueryChanged(true);
}

setSearchParameters(args: IFindInFilesArgs = {}): void {
if (typeof args.isCaseSensitive === 'boolean') {
this.searchWidget.searchInput.setCaseSensitive(args.isCaseSensitive);
}
if (typeof args.matchWholeWord === 'boolean') {
this.searchWidget.searchInput.setWholeWords(args.matchWholeWord);
}
if (typeof args.isRegex === 'boolean') {
this.searchWidget.searchInput.setRegex(args.isRegex);
}
if (typeof args.filesToInclude === 'string') {
this.searchIncludePattern.setValue(String(args.filesToInclude));
}
if (typeof args.filesToExclude === 'string') {
this.searchExcludePattern.setValue(String(args.filesToExclude));
}
if (typeof args.query === 'string') {
this.searchWidget.searchInput.setValue(args.query);
}
if (typeof args.replace === 'string') {
this.searchWidget.replaceInput.value = args.replace;
} else {
if (this.searchWidget.replaceInput.value !== '') {
this.searchWidget.replaceInput.value = '';
}
}
if (typeof args.triggerSearch === 'boolean' && args.triggerSearch) {
this.onQueryChanged(true);
}
}

toggleQueryDetails(moveFocus = true, show?: boolean, skipLayout?: boolean, reverse?: boolean): void {
const cls = 'more';
show = typeof show === 'undefined' ? !dom.hasClass(this.queryDetails, cls) : Boolean(show);
Expand Down