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
This commit is contained in:
Kodai Nakamura 2020-04-11 08:50:40 +09:00 committed by GitHub
parent b02e2efb9d
commit be3df0a396
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 3 deletions

View file

@ -8,6 +8,7 @@ import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
export const OpenInEditorCommandId = 'search.action.openInEditor';
export const OpenNewEditorCommandId = 'search.action.openNewEditor';
export const OpenNewEditorToSideCommandId = 'search.action.openNewEditorToSide';
export const FocusQueryEditorWidgetCommandId = 'search.action.focusQueryEditorWidget';
export const ToggleSearchEditorCaseSensitiveCommandId = 'toggleSearchEditorCaseSensitive';
export const ToggleSearchEditorWholeWordCommandId = 'toggleSearchEditorWholeWord';

View file

@ -26,7 +26,7 @@ import { Extensions as EditorInputExtensions, IEditorInputFactory, IEditorInputF
import * as SearchConstants from 'vs/workbench/contrib/search/common/constants';
import * as SearchEditorConstants from 'vs/workbench/contrib/searchEditor/browser/constants';
import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditor';
import { modifySearchEditorContextLinesCommand, OpenResultsInEditorAction, OpenSearchEditorAction, OpenSearchEditorToSideAction, RerunSearchEditorSearchAction, selectAllSearchEditorMatchesCommand, toggleSearchEditorCaseSensitiveCommand, toggleSearchEditorContextLinesCommand, toggleSearchEditorRegexCommand, toggleSearchEditorWholeWordCommand } from 'vs/workbench/contrib/searchEditor/browser/searchEditorActions';
import { modifySearchEditorContextLinesCommand, OpenResultsInEditorAction, OpenSearchEditorAction, OpenSearchEditorToSideAction, RerunSearchEditorSearchAction, selectAllSearchEditorMatchesCommand, toggleSearchEditorCaseSensitiveCommand, toggleSearchEditorContextLinesCommand, toggleSearchEditorRegexCommand, toggleSearchEditorWholeWordCommand, FocusQueryEditorWidgetAction } from 'vs/workbench/contrib/searchEditor/browser/searchEditorActions';
import { getOrMakeSearchEditorInput, SearchEditorInput, SearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { parseSavedSearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditorSerialization';
@ -209,6 +209,10 @@ registry.registerWorkbenchAction(
registry.registerWorkbenchAction(SyncActionDescriptor.create(RerunSearchEditorSearchAction, RerunSearchEditorSearchAction.ID, RerunSearchEditorSearchAction.LABEL,
{ mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_R } }, ContextKeyExpr.and(SearchEditorConstants.InSearchEditor)),
'Search Editor: Search Again', category);
registry.registerWorkbenchAction(SyncActionDescriptor.create(FocusQueryEditorWidgetAction, FocusQueryEditorWidgetAction.ID, FocusQueryEditorWidgetAction.LABEL,
{ primary: KeyCode.Escape }, ContextKeyExpr.and(SearchEditorConstants.InSearchEditor)),
'Search Editor: Focus Query Editor Widget', category);
//#endregion

View file

@ -224,8 +224,6 @@ export class SearchEditor extends BaseTextEditor {
this._register(this.onDidBlur(() => this.saveViewState()));
this._register(this.searchResultEditor.onKeyDown(e => e.keyCode === KeyCode.Escape && this.queryEditorWidget.searchInput.focus()));
this._register(this.searchResultEditor.onDidChangeModelContent(() => this.getInput()?.setDirty(true)));
[this.queryEditorWidget.searchInputFocusTracker, this.queryEditorWidget.replaceInputFocusTracker, this.inputPatternExcludes.inputFocusTracker, this.inputPatternIncludes.inputFocusTracker]
@ -248,6 +246,13 @@ export class SearchEditor extends BaseTextEditor {
}
}
focusSearchInput() {
const viewState = this.loadViewState();
if (viewState && viewState.focused === 'editor') {
this.queryEditorWidget.searchInput.focus();
}
}
focusNextInput() {
if (this.queryEditorWidget.searchInputHasFocus()) {
if (this.showingIncludesExcludes) {

View file

@ -158,6 +158,24 @@ export class RerunSearchEditorSearchAction extends Action {
}
}
export class FocusQueryEditorWidgetAction extends Action {
static readonly ID: string = Constants.FocusQueryEditorWidgetCommandId;
static readonly LABEL = localize('search.action.focusQueryEditorWidget', "Focus Query Editor Widget");
constructor(id: string, label: string,
@IEditorService private readonly editorService: IEditorService,
) {
super(id, label);
}
async run() {
const input = this.editorService.activeEditor;
if (input instanceof SearchEditorInput) {
(this.editorService.activeEditorPane as SearchEditor).focusSearchInput();
}
}
}
const openNewSearchEditor =
async (accessor: ServicesAccessor, toSide = false) => {
const editorService = accessor.get(IEditorService);