Skip to content

Commit

Permalink
Implemented prefilling quickOpen with last search input.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel73 committed Sep 17, 2018
1 parent 0819493 commit bab1003
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/vs/base/parts/quickopen/browser/quickOpenWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface IShowOptions {
quickNavigateConfiguration?: IQuickNavigateConfiguration;
autoFocus?: IAutoFocus;
inputSelection?: IRange;
value?: string;
}

export class QuickOpenController extends DefaultController {
Expand Down Expand Up @@ -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 : {});
}

Expand All @@ -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);
Expand Down
31 changes: 27 additions & 4 deletions src/vs/workbench/browser/parts/quickopen/quickOpenController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -68,6 +68,10 @@ export class QuickOpenController extends Component implements IQuickOpenService
private readonly _onHide: Emitter<void> = this._register(new Emitter<void>());
get onHide(): Event<void> { 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<QuickOpenHandler>; } = Object.create(null);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -169,7 +174,8 @@ export class QuickOpenController extends Component implements IQuickOpenService
this.quickOpenWidget = this._register(new QuickOpenWidget(
this.partService.getWorkbenchElement(),
{
onOk: () => { /* ignore */ },
// onOk: () => { /* ignore */ },
onOk: () => this.onOk(),
onCancel: () => { /* ignore */ },
onType: (value: string) => this.onType(value || ''),
onShow: () => this.handleOnShow(),
Expand Down Expand Up @@ -216,8 +222,11 @@ export class QuickOpenController extends Component implements IQuickOpenService
// Update context
const registry = Registry.as<IQuickOpenRegistry>(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 });
}
}
}

Expand Down Expand Up @@ -323,6 +332,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
Expand Down Expand Up @@ -360,18 +375,26 @@ 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;
}

let resultPromise: TPromise<void>;
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);
}

Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/browser/quickopen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/electron-browser/main.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down

0 comments on commit bab1003

Please sign in to comment.