From faee920b65f2d89eaaf8c686e06bd39c4cac929f Mon Sep 17 00:00:00 2001 From: Jackson Kearl Date: Mon, 27 Jan 2020 17:37:32 -0800 Subject: [PATCH] move cursor to 0,0 on search --- .../contrib/search/browser/searchActions.ts | 2 +- .../contrib/search/browser/searchEditor.ts | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/contrib/search/browser/searchActions.ts b/src/vs/workbench/contrib/search/browser/searchActions.ts index 85cde05c712..38fa9a428bd 100644 --- a/src/vs/workbench/contrib/search/browser/searchActions.ts +++ b/src/vs/workbench/contrib/search/browser/searchActions.ts @@ -587,7 +587,7 @@ export class ReRunSearchEditorSearchAction extends Action { async run() { const input = this.editorService.activeEditor; if (input instanceof SearchEditorInput) { - await (this.editorService.activeControl as SearchEditor).runSearch(); + await (this.editorService.activeControl as SearchEditor).runSearch(false, true); } } } diff --git a/src/vs/workbench/contrib/search/browser/searchEditor.ts b/src/vs/workbench/contrib/search/browser/searchEditor.ts index d7863b4565a..0e68d535d44 100644 --- a/src/vs/workbench/contrib/search/browser/searchEditor.ts +++ b/src/vs/workbench/contrib/search/browser/searchEditor.ts @@ -96,9 +96,9 @@ export class SearchEditor extends BaseEditor { this.queryEditorWidget = this._register(this.instantiationService.createInstance(SearchWidget, this.queryEditorContainer, { _hideReplaceToggle: true, showContextToggle: true })); this._register(this.queryEditorWidget.onReplaceToggled(() => this.reLayout())); this._register(this.queryEditorWidget.onDidHeightChange(() => this.reLayout())); - this.queryEditorWidget.onSearchSubmit(() => this.runSearch(true)); // onSearchSubmit has an internal delayer, so skip over ours. - this.queryEditorWidget.searchInput.onDidOptionChange(() => this.runSearch()); - this.queryEditorWidget.onDidToggleContext(() => this.runSearch()); + this.queryEditorWidget.onSearchSubmit(() => this.runSearch(true, true)); // onSearchSubmit has an internal delayer, so skip over ours. + this.queryEditorWidget.searchInput.onDidOptionChange(() => this.runSearch(false)); + this.queryEditorWidget.onDidToggleContext(() => this.runSearch(false)); // Includes/Excludes Dropdown this.includesExcludesContainer = DOM.append(this.queryEditorContainer, DOM.$('.includes-excludes')); @@ -217,26 +217,31 @@ export class SearchEditor extends BaseEditor { toggleWholeWords() { this.queryEditorWidget.searchInput.setWholeWords(!this.queryEditorWidget.searchInput.getWholeWords()); - this.runSearch(); + this.runSearch(false); } toggleRegex() { this.queryEditorWidget.searchInput.setRegex(!this.queryEditorWidget.searchInput.getRegex()); - this.runSearch(); + this.runSearch(false); } toggleCaseSensitive() { this.queryEditorWidget.searchInput.setCaseSensitive(!this.queryEditorWidget.searchInput.getCaseSensitive()); - this.runSearch(); + this.runSearch(false); } toggleContextLines() { this.queryEditorWidget.toggleContextLines(); } - async runSearch(instant = false) { + async runSearch(resetCursor = true, instant = false) { if (!this.pauseSearching) { - this.runSearchDelayer.trigger(() => this.doRunSearch(), instant ? 0 : undefined); + this.runSearchDelayer.trigger(async () => { + await this.doRunSearch(); + if (resetCursor) { + this.searchResultEditor.setSelection(new Range(1, 1, 1, 1)); + } + }, instant ? 0 : undefined); } } -- GitLab