From 59213a4c2797e532c59bb9b1463684b688e34fb2 Mon Sep 17 00:00:00 2001 From: Jackson Kearl Date: Fri, 10 Jan 2020 16:20:59 -0800 Subject: [PATCH] Keep track of query includes/excludes expansion state --- .../contrib/search/browser/searchEditor.ts | 21 ++++++++++++------- .../search/browser/searchEditorCommands.ts | 6 ++++-- .../contrib/search/browser/searchWidget.ts | 5 ++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/vs/workbench/contrib/search/browser/searchEditor.ts b/src/vs/workbench/contrib/search/browser/searchEditor.ts index 8e7e247f519..505ea541890 100644 --- a/src/vs/workbench/contrib/search/browser/searchEditor.ts +++ b/src/vs/workbench/contrib/search/browser/searchEditor.ts @@ -57,6 +57,7 @@ export class SearchEditor extends BaseEditor { private runSearchDelayer = new Delayer(300); private pauseSearching: boolean = false; + private showingIncludesExcludes: boolean = false; constructor( @ITelemetryService telemetryService: ITelemetryService, @@ -82,7 +83,7 @@ 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()); + 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()); @@ -92,14 +93,14 @@ export class SearchEditor extends BaseEditor { this.toggleQueryDetailsButton = DOM.append(this.includesExcludesContainer, DOM.$('.expand.codicon.codicon-ellipsis', { tabindex: 0, role: 'button', title: localize('moreSearch', "Toggle Search Details") })); this._register(DOM.addDisposableListener(this.toggleQueryDetailsButton, DOM.EventType.CLICK, e => { DOM.EventHelper.stop(e); - this.toggleQueryDetails(); + this.toggleIncludesExcludes(); })); this._register(DOM.addDisposableListener(this.toggleQueryDetailsButton, DOM.EventType.KEY_UP, (e: KeyboardEvent) => { const event = new StandardKeyboardEvent(e); if (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) { DOM.EventHelper.stop(e); - this.toggleQueryDetails(); + this.toggleIncludesExcludes(); } })); this._register(DOM.addDisposableListener(this.toggleQueryDetailsButton, DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => { @@ -159,9 +160,9 @@ export class SearchEditor extends BaseEditor { }); } - private async runSearch() { + private async runSearch(instant = false) { if (!this.pauseSearching) { - this.runSearchDelayer.trigger(() => this.doRunSearch()); + this.runSearchDelayer.trigger(() => this.doRunSearch(), instant ? 0 : undefined); } } @@ -176,7 +177,8 @@ export class SearchEditor extends BaseEditor { query: this.queryEditorWidget.searchInput.getValue(), regexp: this.queryEditorWidget.searchInput.getRegex(), wholeWord: this.queryEditorWidget.searchInput.getWholeWords(), - useIgnores: this.inputPatternExcludes.useExcludesAndIgnoreFiles() + useIgnores: this.inputPatternExcludes.useExcludesAndIgnoreFiles(), + showIncludesExcludes: this.showingIncludesExcludes }; const content: IPatternInfo = { @@ -264,15 +266,16 @@ export class SearchEditor extends BaseEditor { this.inputPatternExcludes.setValue(newInput.config.excludes); this.inputPatternIncludes.setValue(newInput.config.includes); this.inputPatternExcludes.setUseExcludesAndIgnoreFiles(newInput.config.useIgnores); + this.toggleIncludesExcludes(newInput.config.showIncludesExcludes); this.focusInput(); await super.setInput(newInput, options, token); this.pauseSearching = false; } - toggleQueryDetails(): void { + private toggleIncludesExcludes(_shouldShow?: boolean): void { const cls = 'expanded'; - const shouldShow = !DOM.hasClass(this.includesExcludesContainer, cls); + const shouldShow = _shouldShow ?? !DOM.hasClass(this.includesExcludesContainer, cls); if (shouldShow) { this.toggleQueryDetailsButton.setAttribute('aria-expanded', 'true'); @@ -282,6 +285,8 @@ export class SearchEditor extends BaseEditor { DOM.removeClass(this.includesExcludesContainer, cls); } + this.showingIncludesExcludes = DOM.hasClass(this.includesExcludesContainer, cls); + this.reLayout(); } diff --git a/src/vs/workbench/contrib/search/browser/searchEditorCommands.ts b/src/vs/workbench/contrib/search/browser/searchEditorCommands.ts index d6735a62c12..8156667cbaa 100644 --- a/src/vs/workbench/contrib/search/browser/searchEditorCommands.ts +++ b/src/vs/workbench/contrib/search/browser/searchEditorCommands.ts @@ -39,7 +39,8 @@ export type SearchConfiguration = { wholeWord: boolean, caseSensitive: boolean, regexp: boolean, - useIgnores: boolean + useIgnores: boolean, + showIncludesExcludes: boolean, }; let searchEditorInputInstances = 0; @@ -57,7 +58,7 @@ export class SearchEditorInput extends EditorInput { super(); if (config === undefined) { - this.config = { query: '', includes: '', excludes: '', contextLines: 0, wholeWord: false, caseSensitive: false, regexp: false, useIgnores: true }; + this.config = { query: '', includes: '', excludes: '', contextLines: 0, wholeWord: false, caseSensitive: false, regexp: false, useIgnores: true, showIncludesExcludes: false }; } else { this.config = config; } @@ -416,6 +417,7 @@ export const createEditorFromSearchResult = excludes: rawExcludePattern, contextLines: 0, useIgnores: !searchResult.query.userDisabledExcludesAndIgnoreFiles, + showIncludesExcludes: !!(rawExcludePattern || rawExcludePattern || searchResult.query.userDisabledExcludesAndIgnoreFiles) }), { pinned: true }) as SearchEditor; diff --git a/src/vs/workbench/contrib/search/browser/searchWidget.ts b/src/vs/workbench/contrib/search/browser/searchWidget.ts index 402f4313f1a..95f74747c93 100644 --- a/src/vs/workbench/contrib/search/browser/searchWidget.ts +++ b/src/vs/workbench/contrib/search/browser/searchWidget.ts @@ -160,7 +160,6 @@ export class SearchWidget extends Widget { private temporarilySkipSearchOnChange = false; private showContextCheckbox!: Checkbox; private contextLinesInput!: InputBox; - private _contextLineInputDelayer: Delayer; constructor( container: HTMLElement, @@ -179,7 +178,6 @@ export class SearchWidget extends Widget { this.replaceInputBoxFocused = Constants.ReplaceInputBoxFocusedKey.bindTo(this.contextKeyService); this._replaceHistoryDelayer = new Delayer(500); - this._contextLineInputDelayer = new Delayer(300); this._searchDelayer = this._register(new Delayer(this.searchConfiguration.searchOnTypeDebouncePeriod)); this.render(container, options); @@ -386,7 +384,7 @@ export class SearchWidget extends Widget { if (this.contextLinesInput.value.includes('-')) { this.contextLinesInput.value = '0'; } - this._contextLineInputDelayer.trigger(() => this._onDidToggleContext.fire()); + this._onDidToggleContext.fire(); })); dom.append(searchInputContainer, this.showContextCheckbox.domNode); } @@ -400,6 +398,7 @@ export class SearchWidget extends Widget { this.showContextCheckbox.checked = true; this.contextLinesInput.value = '' + lines; } + dom.toggleClass(this.domNode, 'show-context', this.showContextCheckbox.checked); } private renderReplaceInput(parent: HTMLElement, options: ISearchWidgetOptions): void { -- GitLab