diff --git a/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts b/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts index aca936974b6ae..1a6225fe47bf9 100644 --- a/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts +++ b/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts @@ -58,6 +58,7 @@ export interface IShowOptions { quickNavigateConfiguration?: IQuickNavigateConfiguration; autoFocus?: IAutoFocus; inputSelection?: IRange; + value?: string; } export class QuickOpenController extends DefaultController { @@ -599,6 +600,9 @@ export class QuickOpenWidget extends Disposable implements IModelProvider { if (types.isString(param)) { this.doShowWithPrefix(param); } else { + if (options.value) { + this.restoreLastInput(options.value); + } this.doShowWithInput(param, options && options.autoFocus ? options.autoFocus : {}); } @@ -612,6 +616,12 @@ export class QuickOpenWidget extends Disposable implements IModelProvider { } } + private restoreLastInput(lastInput: string) { + this.inputBox.value = lastInput; + this.inputBox.select(); + this.callbacks.onType(lastInput); + } + private doShowWithPrefix(prefix: string): void { this.inputBox.value = prefix; this.callbacks.onType(prefix); diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index 4a561b7c681b9..b3d0f8b205db8 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -29,7 +29,7 @@ import { EditorInput, IWorkbenchEditorConfiguration, IEditorInput } from 'vs/wor import { Component } from 'vs/workbench/common/component'; import { Event, Emitter } from 'vs/base/common/event'; import { IPartService } from 'vs/workbench/services/part/common/partService'; -import { QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry, CLOSE_ON_FOCUS_LOST_CONFIG, SEARCH_EDITOR_HISTORY } from 'vs/workbench/browser/quickopen'; +import { QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry, CLOSE_ON_FOCUS_LOST_CONFIG, SEARCH_EDITOR_HISTORY, PREFILL_CONFIG } from 'vs/workbench/browser/quickopen'; import * as errors from 'vs/base/common/errors'; import { IQuickOpenService, IShowOptions } from 'vs/platform/quickOpen/common/quickOpen'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; @@ -68,6 +68,10 @@ export class QuickOpenController extends Component implements IQuickOpenService private readonly _onHide: Emitter = this._register(new Emitter()); get onHide(): Event { return this._onHide.event; } + private prefill: boolean; + private isQuickOpen: boolean; + private lastInputValue: string; + private lastSubmittedInputValue: string; private quickOpenWidget: QuickOpenWidget; private dimension: Dimension; private mapResolvedHandlersToPrefix: { [prefix: string]: TPromise; } = Object.create(null); @@ -112,6 +116,7 @@ export class QuickOpenController extends Component implements IQuickOpenService } else { this.closeOnFocusLost = this.configurationService.getValue(CLOSE_ON_FOCUS_LOST_CONFIG); } + this.prefill = this.configurationService.getValue(PREFILL_CONFIG); this.searchInEditorHistory = this.configurationService.getValue(SEARCH_EDITOR_HISTORY); } @@ -169,7 +174,7 @@ export class QuickOpenController extends Component implements IQuickOpenService this.quickOpenWidget = this._register(new QuickOpenWidget( this.partService.getWorkbenchElement(), { - onOk: () => { /* ignore */ }, + onOk: () => this.onOk(), onCancel: () => { /* ignore */ }, onType: (value: string) => this.onType(value || ''), onShow: () => this.handleOnShow(), @@ -216,8 +221,11 @@ export class QuickOpenController extends Component implements IQuickOpenService // Update context const registry = Registry.as(Extensions.Quickopen); this.setQuickOpenContextKey(registry.getDefaultQuickOpenHandler().contextKey); - - this.quickOpenWidget.show(editorHistory, { quickNavigateConfiguration, autoFocus, inputSelection }); + if (this.prefill) { + this.quickOpenWidget.show(editorHistory, { value: this.lastSubmittedInputValue, quickNavigateConfiguration, autoFocus, inputSelection }); + } else { + this.quickOpenWidget.show(editorHistory, { quickNavigateConfiguration, autoFocus, inputSelection }); + } } } @@ -323,6 +331,12 @@ export class QuickOpenController extends Component implements IQuickOpenService return new QuickOpenModel(entries, this.actionProvider); } + private onOk(): void { + if (this.isQuickOpen) { + this.lastSubmittedInputValue = this.lastInputValue; + } + } + private onType(value: string): void { // cancel any pending get results invocation and create new @@ -360,6 +374,10 @@ export class QuickOpenController extends Component implements IQuickOpenService this.quickOpenWidget.setInput(this.getEditorHistoryWithGroupLabel(), { autoFocusFirstEntry: true }); + // If quickOpen entered empty we have to clear the prefill-cache + this.lastInputValue = ''; + this.isQuickOpen = true; + return; } @@ -367,11 +385,15 @@ export class QuickOpenController extends Component implements IQuickOpenService let resultPromiseDone = false; if (handlerDescriptor) { + this.isQuickOpen = false; resultPromise = this.handleSpecificHandler(handlerDescriptor, value, pendingResultsInvocationToken); } // Otherwise handle default handlers if no specific handler present else { + this.isQuickOpen = true; + // Cache the value for prefilling the quickOpen next time is opened + this.lastInputValue = trimmedValue; resultPromise = this.handleDefaultHandler(defaultHandlerDescriptor, value, pendingResultsInvocationToken); } diff --git a/src/vs/workbench/browser/quickopen.ts b/src/vs/workbench/browser/quickopen.ts index 7d6023229266c..d1fb1d08f89f5 100644 --- a/src/vs/workbench/browser/quickopen.ts +++ b/src/vs/workbench/browser/quickopen.ts @@ -22,6 +22,7 @@ import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/ import { CancellationToken } from 'vs/base/common/cancellation'; export const CLOSE_ON_FOCUS_LOST_CONFIG = 'workbench.quickOpen.closeOnFocusLost'; +export const PREFILL_CONFIG = 'workbench.quickOpen.prefill'; export const SEARCH_EDITOR_HISTORY = 'search.quickOpen.includeHistory'; export interface IWorkbenchQuickOpenConfiguration { diff --git a/src/vs/workbench/electron-browser/main.contribution.ts b/src/vs/workbench/electron-browser/main.contribution.ts index b4a27fe13368b..d1e2f3fc62671 100644 --- a/src/vs/workbench/electron-browser/main.contribution.ts +++ b/src/vs/workbench/electron-browser/main.contribution.ts @@ -578,6 +578,11 @@ configurationRegistry.registerConfiguration({ 'description': nls.localize('closeOnFocusLost', "Controls whether Quick Open should close automatically once it loses focus."), 'default': true }, + 'workbench.quickOpen.prefill': { + 'type': 'boolean', + 'description': nls.localize('workbench.quickOpen.prefill', "Controls whether to prefill the Quick Open with last input."), + 'default': true + }, 'workbench.settings.openDefaultSettings': { 'type': 'boolean', 'description': nls.localize('openDefaultSettings', "Controls whether opening settings also opens an editor showing all default settings."),