Skip to content

Commit 1c8c9cf

Browse files
committed
differentiate between pick and preview, microsoft#96489
1 parent c78b1d7 commit 1c8c9cf

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

src/vs/workbench/contrib/codeEditor/browser/quickaccess/gotoSymbolQuickAccess.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
1212
import { IQuickAccessRegistry, Extensions as QuickaccessExtensions } from 'vs/platform/quickinput/common/quickAccess';
1313
import { AbstractGotoSymbolQuickAccessProvider, IGotoSymbolQuickPickItem } from 'vs/editor/contrib/quickAccess/gotoSymbolQuickAccess';
1414
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
15-
import { IWorkbenchEditorConfiguration, IEditorPane } from 'vs/workbench/common/editor';
15+
import { IWorkbenchEditorConfiguration, IEditorPane, IVisibleEditorPane } from 'vs/workbench/common/editor';
1616
import { ITextModel } from 'vs/editor/common/model';
1717
import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
1818
import { timeout } from 'vs/base/common/async';
@@ -108,11 +108,13 @@ export class GotoSymbolQuickAccessProvider extends AbstractGotoSymbolQuickAccess
108108

109109
protected provideWithoutTextEditor(picker: IQuickPick<IGotoSymbolQuickPickItem>): IDisposable {
110110
const pane = this.editorService.activeEditorPane;
111-
if (!pane || !TableOfContentsProviderRegistry.has(pane.getId())) {
112-
//
113-
return super.provideWithoutTextEditor(picker);
111+
if (pane && TableOfContentsProviderRegistry.has(pane.getId())) {
112+
return this.doGetTableOfContentsPicks(picker, pane);
114113
}
114+
return super.provideWithoutTextEditor(picker);
115+
}
115116

117+
private doGetTableOfContentsPicks(picker: IQuickPick<IGotoSymbolQuickPickItem>, pane: IVisibleEditorPane): IDisposable {
116118
const provider = TableOfContentsProviderRegistry.get(pane.getId())!;
117119
const cts = new CancellationTokenSource();
118120

@@ -144,7 +146,7 @@ export class GotoSymbolQuickAccessProvider extends AbstractGotoSymbolQuickAccess
144146
disposables.add(picker.onDidAccept(() => {
145147
picker.hide();
146148
const [entry] = picker.selectedItems;
147-
entries[entry.index]?.reveal();
149+
entries[entry.index]?.pick();
148150
}));
149151

150152
const updatePickerItems = () => {
@@ -177,14 +179,11 @@ export class GotoSymbolQuickAccessProvider extends AbstractGotoSymbolQuickAccess
177179
let ignoreFirstActiveEvent = true;
178180
disposables.add(picker.onDidChangeActive(() => {
179181
const [entry] = picker.activeItems;
180-
181182
if (entry && entries[entry.index]) {
182-
if (ignoreFirstActiveEvent) {
183-
ignoreFirstActiveEvent = false;
184-
return;
183+
if (!ignoreFirstActiveEvent) {
184+
entries[entry.index]?.preview();
185185
}
186-
187-
entries[entry.index]?.reveal();
186+
ignoreFirstActiveEvent = false;
188187
}
189188
}));
190189

@@ -238,7 +237,8 @@ export interface ITableOfContentsEntry {
238237
label: string;
239238
detail?: string;
240239
description?: string;
241-
reveal(): any;
240+
pick(): any;
241+
preview(): any;
242242
}
243243

244244
export interface ITableOfContentsProvider<T extends IEditorPane = IEditorPane> {

src/vs/workbench/contrib/notebook/browser/contrib/toc/tocProvider.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ TableOfContentsProviderRegistry.register(NotebookEditor.ID, new class implements
1414
return undefined;
1515
}
1616
// return an entry per markdown header
17-
const editorWidget = editor.getControl();
17+
const notebookWidget = editor.getControl();
1818
const result: ITableOfContentsEntry[] = [];
1919
for (let cell of editor.viewModel.viewCells) {
2020
const content = cell.getText();
@@ -28,10 +28,14 @@ TableOfContentsProviderRegistry.register(NotebookEditor.ID, new class implements
2828
result.push({
2929
icon: cell.cellKind === CellKind.Markdown ? Codicon.markdown : Codicon.code,
3030
label: matches[j].replace(/^[ \t]*(\#+)/, ''),
31-
reveal: () => {
32-
editorWidget.revealInCenterIfOutsideViewport(cell);
33-
editorWidget.selectElement(cell);
34-
// editor.focusNotebookCell(cell, 'container');
31+
pick() {
32+
notebookWidget.revealInCenterIfOutsideViewport(cell);
33+
notebookWidget.selectElement(cell);
34+
notebookWidget.focusNotebookCell(cell, 'container');
35+
},
36+
preview() {
37+
notebookWidget.revealInCenterIfOutsideViewport(cell);
38+
notebookWidget.selectElement(cell);
3539
}
3640
});
3741
}

0 commit comments

Comments
 (0)