From 4b1fcff7c93ac754fbc4d5beac87e657c66e3901 Mon Sep 17 00:00:00 2001 From: "wim_spaargaren@live.nl" Date: Fri, 3 Mar 2017 08:13:10 +0100 Subject: [PATCH 1/6] proposal to fix issue 21600 --- .../parts/search/browser/searchWidget.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/parts/search/browser/searchWidget.ts b/src/vs/workbench/parts/search/browser/searchWidget.ts index ebc7e20e31ed5..0ba8525d11362 100644 --- a/src/vs/workbench/parts/search/browser/searchWidget.ts +++ b/src/vs/workbench/parts/search/browser/searchWidget.ts @@ -108,9 +108,12 @@ export class SearchWidget extends Widget { private _onReplaceAll = this._register(new Emitter()); public onReplaceAll: Event = this._onReplaceAll.event; + private hasBeenCleared: boolean; + constructor(container: Builder, private contextViewService: IContextViewService, options: ISearchWidgetOptions = Object.create(null), private keyBindingService: IContextKeyService, private keyBindingService2: IKeybindingService, private instantiationService: IInstantiationService) { super(); + this.setHasBeenCleared(false); this.searchHistory = new HistoryNavigator(); this.replaceActive = Constants.ReplaceActiveKey.bindTo(this.keyBindingService); this.searchInputBoxFocussed = Constants.SearchInputBoxFocussedKey.bindTo(this.keyBindingService); @@ -137,12 +140,17 @@ export class SearchWidget extends Widget { } } + public setHasBeenCleared(cleared : boolean): void { + this.hasBeenCleared = cleared; + } + public setWidth(width: number) { this.searchInput.setWidth(width - 2); this.replaceInput.width = width - 28; } public clear() { + this.setHasBeenCleared(true); this.searchInput.clear(); this.replaceInput.value = ''; this.setReplaceAllActionState(false); @@ -170,7 +178,14 @@ export class SearchWidget extends Widget { } public showPreviousSearchTerm() { - let previous = this.searchHistory.previous(); + let previous; + if(this.hasBeenCleared){ + this.setHasBeenCleared(false); + previous = this.searchHistory.current(); + + }else{ + previous = this.searchHistory.previous(); + } if (previous) { this.searchInput.setValue(previous); } From c1d0b0cdc17c2fa7f6d01d8d904e8eac3c963f0e Mon Sep 17 00:00:00 2001 From: Wim Spaargaren Date: Fri, 3 Mar 2017 11:41:41 +0100 Subject: [PATCH 2/6] Adjusted formatting --- src/vs/workbench/parts/search/browser/searchWidget.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/parts/search/browser/searchWidget.ts b/src/vs/workbench/parts/search/browser/searchWidget.ts index 0ba8525d11362..35a939e7df777 100644 --- a/src/vs/workbench/parts/search/browser/searchWidget.ts +++ b/src/vs/workbench/parts/search/browser/searchWidget.ts @@ -140,7 +140,7 @@ export class SearchWidget extends Widget { } } - public setHasBeenCleared(cleared : boolean): void { + public setHasBeenCleared(cleared: boolean): void { this.hasBeenCleared = cleared; } @@ -179,11 +179,10 @@ export class SearchWidget extends Widget { public showPreviousSearchTerm() { let previous; - if(this.hasBeenCleared){ + if (this.hasBeenCleared) { this.setHasBeenCleared(false); - previous = this.searchHistory.current(); - - }else{ + previous = this.searchHistory.current(); + } else { previous = this.searchHistory.previous(); } if (previous) { From cc495baa7165eaaa69c82e2414bf29c688baec1d Mon Sep 17 00:00:00 2001 From: Wim Spaargaren Date: Fri, 3 Mar 2017 11:57:57 +0100 Subject: [PATCH 3/6] Used tslint to format --- src/vs/workbench/parts/search/browser/searchWidget.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/parts/search/browser/searchWidget.ts b/src/vs/workbench/parts/search/browser/searchWidget.ts index 35a939e7df777..bb134d0d1b14d 100644 --- a/src/vs/workbench/parts/search/browser/searchWidget.ts +++ b/src/vs/workbench/parts/search/browser/searchWidget.ts @@ -183,7 +183,7 @@ export class SearchWidget extends Widget { this.setHasBeenCleared(false); previous = this.searchHistory.current(); } else { - previous = this.searchHistory.previous(); + previous = this.searchHistory.previous(); } if (previous) { this.searchInput.setValue(previous); From c714c2fa7ad8e00a95eb7ae1158067cedee5c2b9 Mon Sep 17 00:00:00 2001 From: "wim_spaargaren@live.nl" Date: Fri, 3 Mar 2017 14:34:06 +0100 Subject: [PATCH 4/6] Introduced a better solution for the problem --- src/vs/workbench/parts/search/browser/searchWidget.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/vs/workbench/parts/search/browser/searchWidget.ts b/src/vs/workbench/parts/search/browser/searchWidget.ts index bb134d0d1b14d..6fe164daf55ee 100644 --- a/src/vs/workbench/parts/search/browser/searchWidget.ts +++ b/src/vs/workbench/parts/search/browser/searchWidget.ts @@ -108,12 +108,9 @@ export class SearchWidget extends Widget { private _onReplaceAll = this._register(new Emitter()); public onReplaceAll: Event = this._onReplaceAll.event; - private hasBeenCleared: boolean; - constructor(container: Builder, private contextViewService: IContextViewService, options: ISearchWidgetOptions = Object.create(null), private keyBindingService: IContextKeyService, private keyBindingService2: IKeybindingService, private instantiationService: IInstantiationService) { super(); - this.setHasBeenCleared(false); this.searchHistory = new HistoryNavigator(); this.replaceActive = Constants.ReplaceActiveKey.bindTo(this.keyBindingService); this.searchInputBoxFocussed = Constants.SearchInputBoxFocussedKey.bindTo(this.keyBindingService); @@ -140,17 +137,12 @@ export class SearchWidget extends Widget { } } - public setHasBeenCleared(cleared: boolean): void { - this.hasBeenCleared = cleared; - } - public setWidth(width: number) { this.searchInput.setWidth(width - 2); this.replaceInput.width = width - 28; } public clear() { - this.setHasBeenCleared(true); this.searchInput.clear(); this.replaceInput.value = ''; this.setReplaceAllActionState(false); @@ -179,8 +171,7 @@ export class SearchWidget extends Widget { public showPreviousSearchTerm() { let previous; - if (this.hasBeenCleared) { - this.setHasBeenCleared(false); + if (this.searchInput.getValue().length === 0) { previous = this.searchHistory.current(); } else { previous = this.searchHistory.previous(); From 7e5a2a2a30885d94dfd7064bca78d97f79086667 Mon Sep 17 00:00:00 2001 From: "wim_spaargaren@live.nl" Date: Tue, 7 Mar 2017 07:53:43 +0100 Subject: [PATCH 5/6] The show previous search term now also adds search term to history when not present --- src/vs/base/common/history.ts | 7 +++++++ src/vs/workbench/parts/search/browser/searchWidget.ts | 1 + 2 files changed, 8 insertions(+) diff --git a/src/vs/base/common/history.ts b/src/vs/base/common/history.ts index 466bda628f4b0..6eba18a69c09c 100644 --- a/src/vs/base/common/history.ts +++ b/src/vs/base/common/history.ts @@ -23,6 +23,12 @@ export class HistoryNavigator implements INavigator { this._onChange(); } + public addIfNotPresent(t: T) { + if(!this._history.contains(t)) { + this.add(t); + } + } + public next(): T { if (this._navigator.next()) { return this._navigator.current(); @@ -67,4 +73,5 @@ export class HistoryNavigator implements INavigator { this._history = new ArraySet(data.slice(data.length - this._limit)); } } + } \ No newline at end of file diff --git a/src/vs/workbench/parts/search/browser/searchWidget.ts b/src/vs/workbench/parts/search/browser/searchWidget.ts index 6fe164daf55ee..4d8e55f39bac3 100644 --- a/src/vs/workbench/parts/search/browser/searchWidget.ts +++ b/src/vs/workbench/parts/search/browser/searchWidget.ts @@ -174,6 +174,7 @@ export class SearchWidget extends Widget { if (this.searchInput.getValue().length === 0) { previous = this.searchHistory.current(); } else { + this.searchHistory.addIfNotPresent(this.searchInput.getValue()); previous = this.searchHistory.previous(); } if (previous) { From a5b876903ac58607e4240ff1a31724cc72fa9102 Mon Sep 17 00:00:00 2001 From: "wim_spaargaren@live.nl" Date: Tue, 7 Mar 2017 07:54:18 +0100 Subject: [PATCH 6/6] Formatting issue --- src/vs/base/common/history.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/base/common/history.ts b/src/vs/base/common/history.ts index 6eba18a69c09c..22e921b8d7792 100644 --- a/src/vs/base/common/history.ts +++ b/src/vs/base/common/history.ts @@ -24,7 +24,7 @@ export class HistoryNavigator implements INavigator { } public addIfNotPresent(t: T) { - if(!this._history.contains(t)) { + if (!this._history.contains(t)) { this.add(t); } }