Skip to content

Commit a6e747b

Browse files
author
Jackson Kearl
committed
Add triggerSearch and focusResults search editor args
Closes microsoft#97823
1 parent 1d03c05 commit a6e747b

3 files changed

Lines changed: 24 additions & 13 deletions

File tree

src/vs/workbench/contrib/searchEditor/browser/searchEditor.contribution.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ CommandsRegistry.registerCommand(
213213
//#region Actions
214214
const category = localize('search', "Search Editor");
215215

216+
export type OpenSearchEditorArgs = Partial<SearchConfiguration & { triggerSearch: boolean, focusResults: boolean }>;
216217
const openArgDescription = {
217218
description: 'Open a new search editor. Arguments passed can include variables like ${relativeFileDirname}.',
218219
args: [{
@@ -228,6 +229,8 @@ const openArgDescription = {
228229
regexp: { type: 'boolean' },
229230
useIgnores: { type: 'boolean' },
230231
showIncludesExcludes: { type: 'boolean' },
232+
triggerSearch: { type: 'boolean' },
233+
focusResults: { type: 'boolean' },
231234
}
232235
}
233236
}]
@@ -243,7 +246,7 @@ registerAction2(class extends Action2 {
243246
description: openArgDescription
244247
});
245248
}
246-
async run(accessor: ServicesAccessor, args: Partial<SearchConfiguration>) {
249+
async run(accessor: ServicesAccessor, args: OpenSearchEditorArgs) {
247250
await accessor.get(IInstantiationService).invokeFunction(openNewSearchEditor, args);
248251
}
249252
});
@@ -258,7 +261,7 @@ registerAction2(class extends Action2 {
258261
description: openArgDescription
259262
});
260263
}
261-
async run(accessor: ServicesAccessor, args: Partial<SearchConfiguration>) {
264+
async run(accessor: ServicesAccessor, args: OpenSearchEditorArgs) {
262265
await accessor.get(IInstantiationService).invokeFunction(openNewSearchEditor, args, true);
263266
}
264267
});

src/vs/workbench/contrib/searchEditor/browser/searchEditor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ export class SearchEditor extends BaseTextEditor {
410410
this.searchResultEditor.focus();
411411
}
412412

413-
async triggerSearch(_options?: { resetCursor?: boolean; delay?: number; }) {
413+
async triggerSearch(_options?: { resetCursor?: boolean; delay?: number; focusResults?: boolean }) {
414414
const options = { resetCursor: true, delay: 0, ..._options };
415415

416416
if (!this.pauseSearching) {
@@ -421,6 +421,9 @@ export class SearchEditor extends BaseTextEditor {
421421
this.searchResultEditor.setPosition(new Position(1, 1));
422422
this.searchResultEditor.setScrollPosition({ scrollTop: 0, scrollLeft: 0 });
423423
}
424+
if (options.focusResults) {
425+
this.searchResultEditor.focus();
426+
}
424427
}, options.delay);
425428
}
426429
}

src/vs/workbench/contrib/searchEditor/browser/searchEditorActions.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ILabelService } from 'vs/platform/label/common/label';
1414
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1515
import { SearchResult } from 'vs/workbench/contrib/search/common/searchModel';
1616
import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditor';
17-
import { getOrMakeSearchEditorInput, SearchEditorInput, SearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
17+
import { getOrMakeSearchEditorInput, SearchEditorInput } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
1818
import { serializeSearchResultForEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditorSerialization';
1919
import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
2020
import { ISearchConfigurationProperties } from 'vs/workbench/services/search/common/search';
@@ -25,6 +25,7 @@ import { IHistoryService } from 'vs/workbench/services/history/common/history';
2525
import { Schemas } from 'vs/base/common/network';
2626
import { withNullAsUndefined } from 'vs/base/common/types';
2727
import { OpenNewEditorCommandId } from 'vs/workbench/contrib/searchEditor/browser/constants';
28+
import { OpenSearchEditorArgs } from 'vs/workbench/contrib/searchEditor/browser/searchEditor.contribution';
2829

2930
export const toggleSearchEditorCaseSensitiveCommand = (accessor: ServicesAccessor) => {
3031
const editorService = accessor.get(IEditorService);
@@ -99,7 +100,7 @@ export class OpenSearchEditorAction extends Action {
99100
}
100101

101102
export const openNewSearchEditor =
102-
async (accessor: ServicesAccessor, args: Partial<SearchConfiguration> = {}, toSide = false) => {
103+
async (accessor: ServicesAccessor, _args: OpenSearchEditorArgs = {}, toSide = false) => {
103104
const editorService = accessor.get(IEditorService);
104105
const telemetryService = accessor.get(ITelemetryService);
105106
const instantiationService = accessor.get(IInstantiationService);
@@ -111,11 +112,6 @@ export const openNewSearchEditor =
111112
const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(Schemas.file);
112113
const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined;
113114

114-
const resolvedArgs: Record<string, any> = {};
115-
Object.entries(args).forEach(([name, value]) => {
116-
resolvedArgs[name as any] = (typeof value === 'string') ? configurationResolverService.resolve(lastActiveWorkspaceRoot, value) : value;
117-
});
118-
119115
const activeEditorControl = editorService.activeTextEditorControl;
120116
let activeModel: ICodeEditor | undefined;
121117
let selected = '';
@@ -140,11 +136,20 @@ export const openNewSearchEditor =
140136

141137
telemetryService.publicLog2('searchEditor/openNewSearchEditor');
142138

143-
const input = instantiationService.invokeFunction(getOrMakeSearchEditorInput, { config: { query: selected, ...resolvedArgs }, text: '' });
139+
const args: Record<string, any> = { query: selected };
140+
Object.entries(_args).forEach(([name, value]) => {
141+
args[name as any] = (typeof value === 'string') ? configurationResolverService.resolve(lastActiveWorkspaceRoot, value) : value;
142+
});
143+
144+
const input = instantiationService.invokeFunction(getOrMakeSearchEditorInput, { config: args, text: '' });
144145
const editor = await editorService.openEditor(input, { pinned: true }, toSide ? SIDE_GROUP : ACTIVE_GROUP) as SearchEditor;
145146

146-
if (selected && configurationService.getValue<ISearchConfigurationProperties>('search').searchOnType) {
147-
editor.triggerSearch();
147+
const searchOnType = configurationService.getValue<ISearchConfigurationProperties>('search').searchOnType;
148+
if (
149+
args.triggerSearch === true ||
150+
args.triggerSearch !== false && searchOnType && args.query
151+
) {
152+
editor.triggerSearch({ focusResults: args.focusResults !== false });
148153
}
149154
};
150155

0 commit comments

Comments
 (0)