From a0af20d678d686f1596eefa986f028d2c8477449 Mon Sep 17 00:00:00 2001 From: Alec Chan Date: Tue, 13 Nov 2018 22:04:30 -0600 Subject: [PATCH] Issue #62952: Disabled clear button only when all fields are cleared and enabled clear button after any input in search form. --- src/vs/base/browser/ui/inputbox/inputBox.ts | 4 ++++ .../parts/search/browser/patternInputWidget.ts | 5 +++++ .../parts/search/browser/searchActions.ts | 2 +- .../parts/search/browser/searchView.ts | 17 +++++++++++++++++ .../parts/search/browser/searchWidget.ts | 2 +- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/vs/base/browser/ui/inputbox/inputBox.ts b/src/vs/base/browser/ui/inputbox/inputBox.ts index 947e36a2c77..7d3fb59c4e0 100644 --- a/src/vs/base/browser/ui/inputbox/inputBox.ts +++ b/src/vs/base/browser/ui/inputbox/inputBox.ts @@ -520,9 +520,13 @@ export class HistoryInputBox extends InputBox implements IHistoryNavigationWidge private readonly history: HistoryNavigator; + private readonly _onInput = this._register(new Emitter()); + public readonly onInput: Event = this._onInput.event; + constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IHistoryInputOptions) { super(container, contextViewProvider, options); this.history = new HistoryNavigator(options.history, 100); + this.oninput(this.inputElement, (e) => this._onInput.fire()); } public addToHistory(): void { diff --git a/src/vs/workbench/parts/search/browser/patternInputWidget.ts b/src/vs/workbench/parts/search/browser/patternInputWidget.ts index 354d942ac0b..4da7c67ecc6 100644 --- a/src/vs/workbench/parts/search/browser/patternInputWidget.ts +++ b/src/vs/workbench/parts/search/browser/patternInputWidget.ts @@ -41,6 +41,9 @@ export class PatternInputWidget extends Widget { private _onSubmit = this._register(new Emitter()); public onSubmit: CommonEvent = this._onSubmit.event; + private readonly _onInput = this._register(new Emitter()); + public readonly onInput: CommonEvent = this._onInput.event; + private _onCancel = this._register(new Emitter()); public onCancel: CommonEvent = this._onCancel.event; @@ -58,6 +61,8 @@ export class PatternInputWidget extends Widget { this.render(options); + this.oninput(this.inputBox.inputElement, (e) => this._onInput.fire()); + parent.appendChild(this.domNode); } diff --git a/src/vs/workbench/parts/search/browser/searchActions.ts b/src/vs/workbench/parts/search/browser/searchActions.ts index dc23bd390ff..93207c07d80 100644 --- a/src/vs/workbench/parts/search/browser/searchActions.ts +++ b/src/vs/workbench/parts/search/browser/searchActions.ts @@ -317,7 +317,7 @@ export class ClearSearchResultsAction extends Action { update(): void { const searchView = getSearchView(this.viewletService, this.panelService); - this.enabled = searchView && searchView.isSearchSubmitted(); + this.enabled = searchView && !searchView.allSearchFieldsClear();//searchView.isSearchSubmitted(); } public run(): Thenable { diff --git a/src/vs/workbench/parts/search/browser/searchView.ts b/src/vs/workbench/parts/search/browser/searchView.ts index 622455f851e..0dfaa3cffea 100644 --- a/src/vs/workbench/parts/search/browser/searchView.ts +++ b/src/vs/workbench/parts/search/browser/searchView.ts @@ -161,6 +161,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { (() => this.selectCurrentMatch())); this.delayedRefresh = this._register(new Delayer(250)); + } private onDidChangeWorkbenchState(): void { @@ -271,6 +272,11 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { this._register(this.viewModel.searchResult.onChange((event) => this.onSearchResultsChanged(event))); + this._register(this.searchWidget.searchInput.onInput(() => this.updateActions())); + this._register(this.searchWidget.replaceInput.onInput(() => this.updateActions())); + this._register(this.searchIncludePattern.onInput(() => this.updateActions())); + this._register(this.searchExcludePattern.onInput(() => this.updateActions())); + this._register(this.onDidFocus(() => this.viewletFocused.set(true))); this._register(this.onDidBlur(() => this.viewletFocused.set(false))); } @@ -341,6 +347,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { })); this._register(this.searchWidget.onReplaceAll(() => this.replaceAll())); + this.trackInputBox(this.searchWidget.searchInputFocusTracker); this.trackInputBox(this.searchWidget.replaceInputFocusTracker); } @@ -826,6 +833,13 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { return this.searching; } + public allSearchFieldsClear(): boolean { + return this.searchWidget.getReplaceValue() === '' && + this.searchWidget.searchInput.getValue() === '' && + this.searchIncludePattern.getValue() === '' && + this.searchExcludePattern.getValue() === ''; + } + public hasSearchResults(): boolean { return !this.viewModel.searchResult.isEmpty(); } @@ -837,7 +851,10 @@ export class SearchView extends Viewlet implements IViewlet, IPanel { this.showSearchWithoutFolderMessage(); } this.searchWidget.clear(); + this.searchIncludePattern.setValue(''); + this.searchExcludePattern.setValue(''); this.viewModel.cancelSearch(); + this.updateActions(); } public cancelSearch(): boolean { diff --git a/src/vs/workbench/parts/search/browser/searchWidget.ts b/src/vs/workbench/parts/search/browser/searchWidget.ts index 806ce9f553e..1719b158046 100644 --- a/src/vs/workbench/parts/search/browser/searchWidget.ts +++ b/src/vs/workbench/parts/search/browser/searchWidget.ts @@ -89,7 +89,7 @@ export class SearchWidget extends Widget { private searchInputBoxFocused: IContextKey; private replaceContainer: HTMLElement; - private replaceInput: HistoryInputBox; + public replaceInput: HistoryInputBox; private toggleReplaceButton: Button; private replaceAllAction: ReplaceAllAction; private replaceActive: IContextKey; -- GitLab