Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: Improvements to clear button behavior #63082

Merged
merged 4 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class PatternInputWidget extends Widget {
private ariaLabel: string;

private domNode: HTMLElement;
protected inputBox: HistoryInputBox;
public inputBox: HistoryInputBox;

private _onSubmit = this._register(new Emitter<boolean>());
public onSubmit: CommonEvent<boolean> = this._onSubmit.event;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/search/browser/searchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.hasSearchResults());
}

public run(): Thenable<void> {
Expand Down
17 changes: 17 additions & 0 deletions src/vs/workbench/parts/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
(() => this.selectCurrentMatch()));

this.delayedRefresh = this._register(new Delayer<void>(250));

}

private onDidChangeWorkbenchState(): void {
Expand Down Expand Up @@ -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.onDidChange(() => this.updateActions()));
this._register(this.searchIncludePattern.inputBox.onDidChange(() => this.updateActions()));
this._register(this.searchExcludePattern.inputBox.onDidChange(() => this.updateActions()));

this._register(this.onDidFocus(() => this.viewletFocused.set(true)));
this._register(this.onDidBlur(() => this.viewletFocused.set(false)));
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/search/browser/searchWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class SearchWidget extends Widget {
private searchInputBoxFocused: IContextKey<boolean>;

private replaceContainer: HTMLElement;
private replaceInput: HistoryInputBox;
public replaceInput: HistoryInputBox;
private toggleReplaceButton: Button;
private replaceAllAction: ReplaceAllAction;
private replaceActive: IContextKey<boolean>;
Expand Down