提交 5349bf1f 编写于 作者: B Benjamin Pasero

quick access - allow to open in background for local symbols and go to line too

上级 3f684395
......@@ -22,6 +22,10 @@ interface IEditorLineDecoration {
overviewRulerDecorationId: string;
}
export interface IEditorNavigationQuickAccessOptions {
canAcceptInBackground?: boolean;
}
/**
* A reusable quick access provider for the editor with support
* for adding decorations for navigating in the currently active file
......@@ -29,11 +33,16 @@ interface IEditorLineDecoration {
*/
export abstract class AbstractEditorNavigationQuickAccessProvider implements IQuickAccessProvider {
constructor(protected options?: IEditorNavigationQuickAccessOptions) { }
//#region Provider methods
provide(picker: IQuickPick<IQuickPickItem>, token: CancellationToken): IDisposable {
const disposables = new DisposableStore();
// Apply options if any
picker.canAcceptInBackground = !!this.options?.canAcceptInBackground;
// Disable filtering & sorting, we control the results
picker.matchOnLabel = picker.matchOnDescription = picker.matchOnDetail = picker.sortByLabel = false;
......@@ -110,11 +119,13 @@ export abstract class AbstractEditorNavigationQuickAccessProvider implements IQu
*/
protected abstract provideWithoutTextEditor(picker: IQuickPick<IQuickPickItem>, token: CancellationToken): IDisposable;
protected gotoLocation(editor: IEditor, options: { range: IRange, keyMods: IKeyMods, forceSideBySide?: boolean }): void {
protected gotoLocation(editor: IEditor, options: { range: IRange, keyMods: IKeyMods, forceSideBySide?: boolean, preserveFocus?: boolean }): void {
editor.setSelection(options.range);
editor.revealRangeInCenter(options.range, ScrollType.Smooth);
if (!options.preserveFocus) {
editor.focus();
}
}
protected getModel(editor: IEditor | IDiffEditor): ITextModel | undefined {
return isDiffEditor(editor) ?
......
......@@ -18,6 +18,10 @@ export abstract class AbstractGotoLineQuickAccessProvider extends AbstractEditor
static PREFIX = ':';
constructor() {
super({ canAcceptInBackground: true });
}
protected provideWithoutTextEditor(picker: IQuickPick<IGotoLineQuickPickItem>): IDisposable {
const label = localize('cannotRunGotoLine', "Open a text editor first to go to a line.");
......@@ -31,17 +35,19 @@ export abstract class AbstractGotoLineQuickAccessProvider extends AbstractEditor
const disposables = new DisposableStore();
// Goto line once picked
disposables.add(picker.onDidAccept(() => {
disposables.add(picker.onDidAccept(event => {
const [item] = picker.selectedItems;
if (item) {
if (!this.isValidLineNumber(editor, item.lineNumber)) {
return;
}
this.gotoLocation(editor, { range: this.toRange(item.lineNumber, item.column), keyMods: picker.keyMods });
this.gotoLocation(editor, { range: this.toRange(item.lineNumber, item.column), keyMods: picker.keyMods, preserveFocus: event.inBackground });
if (!event.inBackground) {
picker.hide();
}
}
}));
// React to picker changes
......
......@@ -10,12 +10,13 @@ import { DisposableStore, IDisposable, Disposable } from 'vs/base/common/lifecyc
import { IEditor, ScrollType } from 'vs/editor/common/editorCommon';
import { ITextModel } from 'vs/editor/common/model';
import { IRange, Range } from 'vs/editor/common/core/range';
import { AbstractEditorNavigationQuickAccessProvider } from 'vs/editor/contrib/quickAccess/editorNavigationQuickAccess';
import { AbstractEditorNavigationQuickAccessProvider, IEditorNavigationQuickAccessOptions } from 'vs/editor/contrib/quickAccess/editorNavigationQuickAccess';
import { DocumentSymbol, SymbolKinds, SymbolTag, DocumentSymbolProviderRegistry, SymbolKind } from 'vs/editor/common/modes';
import { OutlineModel, OutlineElement } from 'vs/editor/contrib/documentSymbols/outlineModel';
import { values } from 'vs/base/common/collections';
import { trim, format } from 'vs/base/common/strings';
import { fuzzyScore, FuzzyScore, createMatches } from 'vs/base/common/filters';
import { assign } from 'vs/base/common/objects';
interface IGotoSymbolQuickPickItem extends IQuickPickItem {
kind: SymbolKind,
......@@ -24,7 +25,7 @@ interface IGotoSymbolQuickPickItem extends IQuickPickItem {
range?: { decoration: IRange, selection: IRange },
}
export interface IGotoSymbolQuickAccessProviderOptions {
export interface IGotoSymbolQuickAccessProviderOptions extends IEditorNavigationQuickAccessOptions {
openSideBySideDirection: () => undefined | 'right' | 'down'
}
......@@ -34,8 +35,8 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit
static SCOPE_PREFIX = ':';
static PREFIX_BY_CATEGORY = `${AbstractGotoSymbolQuickAccessProvider.PREFIX}${AbstractGotoSymbolQuickAccessProvider.SCOPE_PREFIX}`;
constructor(private options?: IGotoSymbolQuickAccessProviderOptions) {
super();
constructor(protected options?: IGotoSymbolQuickAccessProviderOptions) {
super(assign(options, { canAcceptInBackground: true }));
}
protected provideWithoutTextEditor(picker: IQuickPick<IGotoSymbolQuickPickItem>): IDisposable {
......@@ -92,13 +93,15 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit
const disposables = new DisposableStore();
// Goto symbol once picked
disposables.add(picker.onDidAccept(() => {
disposables.add(picker.onDidAccept(event => {
const [item] = picker.selectedItems;
if (item && item.range) {
this.gotoLocation(editor, { range: item.range.selection, keyMods: picker.keyMods });
this.gotoLocation(editor, { range: item.range.selection, keyMods: picker.keyMods, preserveFocus: event.inBackground });
if (!event.inBackground) {
picker.hide();
}
}
}));
// Goto symbol side by side if enabled
......
......@@ -37,13 +37,14 @@ export class GotoLineQuickAccessProvider extends AbstractGotoLineQuickAccessProv
return this.editorService.activeTextEditorControl;
}
protected gotoLocation(editor: IEditor, options: { range: IRange, keyMods: IKeyMods, forceSideBySide?: boolean }): void {
protected gotoLocation(editor: IEditor, options: { range: IRange, keyMods: IKeyMods, forceSideBySide?: boolean, preserveFocus?: boolean }): void {
// Check for sideBySide use
if ((options.keyMods.ctrlCmd || options.forceSideBySide) && this.editorService.activeEditor) {
this.editorService.openEditor(this.editorService.activeEditor, {
selection: options.range,
pinned: options.keyMods.alt || this.configuration.openEditorPinned
pinned: options.keyMods.alt || this.configuration.openEditorPinned,
preserveFocus: options.preserveFocus
}, SIDE_GROUP);
}
......
......@@ -40,13 +40,14 @@ export class GotoSymbolQuickAccessProvider extends AbstractGotoSymbolQuickAccess
return this.editorService.activeTextEditorControl;
}
protected gotoLocation(editor: IEditor, options: { range: IRange, keyMods: IKeyMods, forceSideBySide?: boolean }): void {
protected gotoLocation(editor: IEditor, options: { range: IRange, keyMods: IKeyMods, forceSideBySide?: boolean, preserveFocus?: boolean }): void {
// Check for sideBySide use
if ((options.keyMods.ctrlCmd || options.forceSideBySide) && this.editorService.activeEditor) {
this.editorService.openEditor(this.editorService.activeEditor, {
selection: options.range,
pinned: options.keyMods.alt || this.configuration.openEditorPinned
pinned: options.keyMods.alt || this.configuration.openEditorPinned,
preserveFocus: options.preserveFocus
}, SIDE_GROUP);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册