Skip to content

Commit

Permalink
select the symbol under cursor when opening quick pick (#154247)
Browse files Browse the repository at this point in the history
fixes #154246
  • Loading branch information
jrieken authored Jul 6, 2022
1 parent 2d0d5b2 commit 01d119a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/vs/editor/contrib/quickAccess/browser/gotoSymbolQuickAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AbstractEditorNavigationQuickAccessProvider, IEditorNavigationQuickAcce
import { localize } from 'vs/nls';
import { IQuickPick, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
import { Position } from 'vs/editor/common/core/position';

export interface IGotoSymbolQuickPickItem extends IQuickPickItem {
kind: SymbolKind;
Expand Down Expand Up @@ -155,7 +156,7 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit

// Set initial picks and update on type
let picksCts: CancellationTokenSource | undefined = undefined;
const updatePickerItems = async () => {
const updatePickerItems = async (positionToEnclose: Position | undefined) => {

// Cancel any previous ask for picks and busy
picksCts?.dispose(true);
Expand All @@ -175,6 +176,13 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit

if (items.length > 0) {
picker.items = items;
if (positionToEnclose && query.original.length === 0) {
const candidate = <IGotoSymbolQuickPickItem | undefined>items.find(item => item.type !== 'separator' && item.range && Range.containsPosition(item.range.decoration, positionToEnclose));
if (candidate) {
picker.activeItems = [candidate];
}
}

} else {
if (query.original.length > 0) {
this.provideLabelPick(picker, localize('noMatchingSymbolResults', "No matching editor symbols"));
Expand All @@ -188,19 +196,19 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit
}
}
};
disposables.add(picker.onDidChangeValue(() => updatePickerItems()));
updatePickerItems();
disposables.add(picker.onDidChangeValue(() => updatePickerItems(undefined)));
updatePickerItems(editor.getSelection()?.getPosition());


// Reveal and decorate when active item changes
// However, ignore the very first event so that
// However, ignore the very first two events so that
// opening the picker is not immediately revealing
// and decorating the first entry.
let ignoreFirstActiveEvent = true;
let ignoreFirstActiveEvent = 2;
disposables.add(picker.onDidChangeActive(() => {
const [item] = picker.activeItems;
if (item && item.range) {
if (ignoreFirstActiveEvent) {
ignoreFirstActiveEvent = false;
if (ignoreFirstActiveEvent-- > 0) {
return;
}

Expand Down

0 comments on commit 01d119a

Please sign in to comment.