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

Prefill quick open #55752

Merged
merged 2 commits into from Oct 1, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/vs/base/parts/quickopen/browser/quickOpenWidget.ts
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
30 changes: 26 additions & 4 deletions src/vs/workbench/browser/parts/quickopen/quickOpenController.ts
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,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(),
Expand Down Expand Up @@ -216,8 +221,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 +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
Expand Down Expand Up @@ -360,18 +374,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
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
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