Skip to content
Closed
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
39 changes: 39 additions & 0 deletions src/vs/workbench/browser/parts/quickopen/quickOpenController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ import { FileKind, IFileService } from 'vs/platform/files/common/files';
import { scoreItem, ScorerCache, compareItemsByScore, prepareQuery } from 'vs/base/parts/quickopen/common/quickOpenScorer';
import { getBaseLabel } from 'vs/base/common/labels';
import { WorkbenchTree } from 'vs/platform/list/browser/listService';
import { getSelectionSearchString } from 'vs/editor/contrib/find/findController';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';

const HELP_PREFIX = '?';

Expand Down Expand Up @@ -538,6 +540,33 @@ export class QuickOpenController extends Component implements IQuickOpenService
}, 100 /* to prevent flashing, we accumulate visibility changes over a timeout of 100ms */);
}

private getSelectedText(): string | null {
const activeEditor = this.editorService.getActiveEditor();

if (!activeEditor) {
return null;
}

const editorControl = activeEditor.getControl() as ICodeEditor | null;

if (!editorControl) {
return null;
}

return getSelectionSearchString(editorControl);
}

private shouldPrefill(prefix?: string): boolean {
const isTurnedOn = this.configurationService.getValue('workbench.quickOpen.prefillFromSelection') as boolean;
const prefixes = this.configurationService.getValue('workbench.quickOpen.prefillPrefixes') as Array<string | null>;

if (!isTurnedOn) {
return false;
}

return prefixes.indexOf(prefix || '') !== -1;
}

public show(prefix?: string, options?: IShowOptions): TPromise<void> {
let quickNavigateConfiguration = options ? options.quickNavigateConfiguration : void 0;
let inputSelection = options ? options.inputSelection : void 0;
Expand Down Expand Up @@ -583,6 +612,16 @@ export class QuickOpenController extends Component implements IQuickOpenService
this.quickOpenWidget.layout(this.layoutDimensions);
}

const selectedText = this.getSelectedText();

if (selectedText && this.shouldPrefill(prefix)) {
inputSelection = {
start: prefix ? prefix.length : 0,
end: selectedText.length + 1
};
prefix = (prefix || '') + selectedText;
}

// Show quick open with prefix or editor history
if (!this.quickOpenWidget.isVisible() || quickNavigateConfiguration) {
if (prefix) {
Expand Down
15 changes: 15 additions & 0 deletions src/vs/workbench/electron-browser/main.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,21 @@ configurationRegistry.registerConfiguration({
'description': nls.localize('closeOnFocusLost', "Controls if Quick Open should close automatically once it loses focus."),
'default': true
},
'workbench.quickOpen.prefillFromSelection': {
'type': 'boolean',
'default': true,
'description': nls.localize('quickopen.prefillFromSelection', "Controls if selected text should prefill quickopen query"),
},
'workbench.quickOpen.prefillPrefixes': {
'type': 'array',
'items': {
'type': 'string'
},
'default': [
'#'
],
'description': nls.localize('quickopen.prefillPrefixes', "Controls which prefixes should be prefilled on quickopen if prefill feature turned on"),
},
'workbench.settings.openDefaultSettings': {
'type': 'boolean',
'description': nls.localize('openDefaultSettings', "Controls if opening settings also opens an editor showing all default settings."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import { QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions as QuickOpen
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { getSelectionSearchString } from 'vs/editor/contrib/find/findController';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { ITree } from 'vs/base/parts/tree/browser/tree';
Expand Down Expand Up @@ -253,25 +251,13 @@ class ShowAllSymbolsAction extends Action {

constructor(
actionId: string, actionLabel: string,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@ICodeEditorService private editorService: ICodeEditorService) {
@IQuickOpenService private quickOpenService: IQuickOpenService) {
super(actionId, actionLabel);
this.enabled = !!this.quickOpenService;
}

public run(context?: any): TPromise<void> {

let prefix = ShowAllSymbolsAction.ALL_SYMBOLS_PREFIX;
let inputSelection: { start: number; end: number; } = void 0;
let editor = this.editorService.getFocusedCodeEditor();
const word = editor && getSelectionSearchString(editor);
if (word) {
prefix = prefix + word;
inputSelection = { start: 1, end: word.length + 1 };
}

this.quickOpenService.show(prefix, { inputSelection });

this.quickOpenService.show(ShowAllSymbolsAction.ALL_SYMBOLS_PREFIX);
return TPromise.as(null);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/services/editor/common/editorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface IWorkbenchEditorService extends IEditorService {
/**
* Returns the currently active editor or null if none.
*/
getActiveEditor(): IEditor;
getActiveEditor(): IEditor | null;

/**
* Returns the currently active editor input or null if none.
Expand Down