提交 a86e6b45 编写于 作者: S Sandeep Somavarapu

Implement Search History #5508

上级 a9b91a0a
......@@ -25,7 +25,7 @@ import {IKeybindings} from 'vs/platform/keybinding/common/keybinding';
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IViewletService} from 'vs/workbench/services/viewlet/common/viewletService';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import {OpenSearchViewletAction, ReplaceInFilesAction, FocusNextInputAction, FocusPreviousInputAction} from 'vs/workbench/parts/search/browser/searchActions';
import {OpenSearchViewletAction, ReplaceInFilesAction, ShowNextSearchTermAction, ShowPreviousSearchTermAction, FocusNextInputAction, FocusPreviousInputAction} from 'vs/workbench/parts/search/browser/searchActions';
import * as Constants from 'vs/workbench/parts/search/common/constants';
import { registerContributions as replaceContributions } from 'vs/workbench/parts/search/browser/replaceContributions';
import { registerContributions as searchWidgetContributions } from 'vs/workbench/parts/search/browser/searchWidget';
......@@ -165,6 +165,14 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(ShowAllSymbolsAction,
primary: KeyMod.CtrlCmd | KeyCode.KEY_T
}), 'Show All Symbols');
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowNextSearchTermAction, ShowNextSearchTermAction.ID, ShowNextSearchTermAction.LABEL, {
primary: KeyMod.Alt | KeyCode.DownArrow
}, ContextKeyExpr.and(Constants.SearchViewletVisibleKey, Constants.SearchInputBoxFocussedKey)), '');
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowPreviousSearchTermAction, ShowPreviousSearchTermAction.ID, ShowPreviousSearchTermAction.LABEL, {
primary: KeyMod.Alt | KeyCode.UpArrow
}, ContextKeyExpr.and(Constants.SearchViewletVisibleKey, Constants.SearchInputBoxFocussedKey)), '');
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusNextInputAction, FocusNextInputAction.ID, FocusNextInputAction.LABEL, {
primary: KeyCode.DownArrow
}, ContextKeyExpr.and(Constants.SearchViewletVisibleKey, Constants.InputBoxFocussedKey)), '');
......
......@@ -39,6 +39,38 @@ export function appendKeyBindingLabel(label: string, keyBinding: any, keyBinding
return label + ' (' + keyBindingService2.getLabelFor(keyBinding) + ')';
}
export class ShowNextSearchTermAction extends Action {
public static ID = 'search.history.nextSearchTerm';
public static LABEL = nls.localize('nextSearchTerm', "Show next search term");
constructor(id: string, label: string, @IViewletService private viewletService: IViewletService) {
super(id, label);
}
public run(): TPromise<any> {
let searchAndReplaceWidget = (<SearchViewlet>this.viewletService.getActiveViewlet()).searchAndReplaceWidget;
searchAndReplaceWidget.showNextSearchTerm();
return TPromise.as(null);
}
}
export class ShowPreviousSearchTermAction extends Action {
public static ID = 'search.history.previousSearchTerm';
public static LABEL = nls.localize('previousSearchTerm', "Show previous search term");
constructor(id: string, label: string, @IViewletService private viewletService: IViewletService) {
super(id, label);
}
public run(): TPromise<any> {
let searchAndReplaceWidget = (<SearchViewlet>this.viewletService.getActiveViewlet()).searchAndReplaceWidget;
searchAndReplaceWidget.showPreviousSearchTerm();
return TPromise.as(null);
}
}
export class FocusNextInputAction extends Action {
public static ID = 'search.focus.nextInputBox';
......
......@@ -25,6 +25,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IViewletService } from 'vs/workbench/services/viewlet/common/viewletService';
import { isSearchViewletFocussed, appendKeyBindingLabel } from 'vs/workbench/parts/search/browser/searchActions';
import { CONTEXT_FIND_WIDGET_NOT_VISIBLE } from 'vs/editor/contrib/find/common/findController';
import { HistoryNavigator } from 'vs/base/common/history';
import * as Constants from 'vs/workbench/parts/search/common/constants';
export interface ISearchWidgetOptions {
......@@ -86,6 +87,8 @@ export class SearchWidget extends Widget {
private replaceActive: IContextKey<boolean>;
private replaceActionBar: ActionBar;
private searchHistory: HistoryNavigator<string>;
private _onSearchSubmit = this._register(new Emitter<boolean>());
public onSearchSubmit: Event<boolean> = this._onSearchSubmit.event;
......@@ -107,6 +110,7 @@ export class SearchWidget extends Widget {
constructor(container: Builder, private contextViewService: IContextViewService, options: ISearchWidgetOptions= Object.create(null),
private keyBindingService: IContextKeyService, private keyBindingService2: IKeybindingService, private instantiationService: IInstantiationService) {
super();
this.searchHistory = new HistoryNavigator<string>();
this.replaceActive = Constants.ReplaceActiveKey.bindTo(this.keyBindingService);
this.searchInputBoxFocussed = Constants.SearchInputBoxFocussedKey.bindTo(this.keyBindingService);
this.render(container, options);
......@@ -156,6 +160,20 @@ export class SearchWidget extends Widget {
}
}
public showNextSearchTerm() {
let next = this.searchHistory.next();
if (next) {
this.searchInput.setValue(next);
}
}
public showPreviousSearchTerm() {
let previous = this.searchHistory.previous();
if (previous) {
this.searchInput.setValue(previous);
}
}
public searchInputHasFocus(): boolean {
return this.searchInputBoxFocussed.get();
}
......@@ -193,6 +211,9 @@ export class SearchWidget extends Widget {
this.searchInput.setRegex(!!options.isRegex);
this.searchInput.setCaseSensitive(!!options.isCaseSensitive);
this.searchInput.setWholeWords(!!options.isWholeWords);
this._register(this.onSearchSubmit(() => {
this.searchHistory.add(this.searchInput.getValue());
}));
this.searchInputFocusTracker = dom.trackFocus(this.searchInput.inputBox.inputElement);
this._register(this.searchInputFocusTracker.addFocusListener(() => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册