Skip to content

Commit be3df0a

Browse files
authored
Add action to focus query editor widget (#94799)
* Add search.action.focusQueryEditorWidget * Implement focusSearchInput method for searchEditor * Add FocusQueryEditorWidgetAction class * Register FocusQueryEditorWidgetAction * Remove existing binding * Add default keybind * Stop toggle focus * Remove mac
1 parent b02e2ef commit be3df0a

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
88
export const OpenInEditorCommandId = 'search.action.openInEditor';
99
export const OpenNewEditorCommandId = 'search.action.openNewEditor';
1010
export const OpenNewEditorToSideCommandId = 'search.action.openNewEditorToSide';
11+
export const FocusQueryEditorWidgetCommandId = 'search.action.focusQueryEditorWidget';
1112

1213
export const ToggleSearchEditorCaseSensitiveCommandId = 'toggleSearchEditorCaseSensitive';
1314
export const ToggleSearchEditorWholeWordCommandId = 'toggleSearchEditorWholeWord';

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { Extensions as EditorInputExtensions, IEditorInputFactory, IEditorInputF
2626
import * as SearchConstants from 'vs/workbench/contrib/search/common/constants';
2727
import * as SearchEditorConstants from 'vs/workbench/contrib/searchEditor/browser/constants';
2828
import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditor';
29-
import { modifySearchEditorContextLinesCommand, OpenResultsInEditorAction, OpenSearchEditorAction, OpenSearchEditorToSideAction, RerunSearchEditorSearchAction, selectAllSearchEditorMatchesCommand, toggleSearchEditorCaseSensitiveCommand, toggleSearchEditorContextLinesCommand, toggleSearchEditorRegexCommand, toggleSearchEditorWholeWordCommand } from 'vs/workbench/contrib/searchEditor/browser/searchEditorActions';
29+
import { modifySearchEditorContextLinesCommand, OpenResultsInEditorAction, OpenSearchEditorAction, OpenSearchEditorToSideAction, RerunSearchEditorSearchAction, selectAllSearchEditorMatchesCommand, toggleSearchEditorCaseSensitiveCommand, toggleSearchEditorContextLinesCommand, toggleSearchEditorRegexCommand, toggleSearchEditorWholeWordCommand, FocusQueryEditorWidgetAction } from 'vs/workbench/contrib/searchEditor/browser/searchEditorActions';
3030
import { getOrMakeSearchEditorInput, SearchEditorInput, SearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
3131
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
3232
import { parseSavedSearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditorSerialization';
@@ -209,6 +209,10 @@ registry.registerWorkbenchAction(
209209
registry.registerWorkbenchAction(SyncActionDescriptor.create(RerunSearchEditorSearchAction, RerunSearchEditorSearchAction.ID, RerunSearchEditorSearchAction.LABEL,
210210
{ mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_R } }, ContextKeyExpr.and(SearchEditorConstants.InSearchEditor)),
211211
'Search Editor: Search Again', category);
212+
213+
registry.registerWorkbenchAction(SyncActionDescriptor.create(FocusQueryEditorWidgetAction, FocusQueryEditorWidgetAction.ID, FocusQueryEditorWidgetAction.LABEL,
214+
{ primary: KeyCode.Escape }, ContextKeyExpr.and(SearchEditorConstants.InSearchEditor)),
215+
'Search Editor: Focus Query Editor Widget', category);
212216
//#endregion
213217

214218

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ export class SearchEditor extends BaseTextEditor {
224224

225225
this._register(this.onDidBlur(() => this.saveViewState()));
226226

227-
this._register(this.searchResultEditor.onKeyDown(e => e.keyCode === KeyCode.Escape && this.queryEditorWidget.searchInput.focus()));
228-
229227
this._register(this.searchResultEditor.onDidChangeModelContent(() => this.getInput()?.setDirty(true)));
230228

231229
[this.queryEditorWidget.searchInputFocusTracker, this.queryEditorWidget.replaceInputFocusTracker, this.inputPatternExcludes.inputFocusTracker, this.inputPatternIncludes.inputFocusTracker]
@@ -248,6 +246,13 @@ export class SearchEditor extends BaseTextEditor {
248246
}
249247
}
250248

249+
focusSearchInput() {
250+
const viewState = this.loadViewState();
251+
if (viewState && viewState.focused === 'editor') {
252+
this.queryEditorWidget.searchInput.focus();
253+
}
254+
}
255+
251256
focusNextInput() {
252257
if (this.queryEditorWidget.searchInputHasFocus()) {
253258
if (this.showingIncludesExcludes) {

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

+18
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,24 @@ export class RerunSearchEditorSearchAction extends Action {
158158
}
159159
}
160160

161+
export class FocusQueryEditorWidgetAction extends Action {
162+
static readonly ID: string = Constants.FocusQueryEditorWidgetCommandId;
163+
static readonly LABEL = localize('search.action.focusQueryEditorWidget', "Focus Query Editor Widget");
164+
165+
constructor(id: string, label: string,
166+
@IEditorService private readonly editorService: IEditorService,
167+
) {
168+
super(id, label);
169+
}
170+
171+
async run() {
172+
const input = this.editorService.activeEditor;
173+
if (input instanceof SearchEditorInput) {
174+
(this.editorService.activeEditorPane as SearchEditor).focusSearchInput();
175+
}
176+
}
177+
}
178+
161179
const openNewSearchEditor =
162180
async (accessor: ServicesAccessor, toSide = false) => {
163181
const editorService = accessor.get(IEditorService);

0 commit comments

Comments
 (0)