提交 1c8c9cf5 编写于 作者: J Johannes Rieken

differentiate between pick and preview, https://github.com/microsoft/vscode/issues/96489

上级 c78b1d7c
......@@ -12,7 +12,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
import { IQuickAccessRegistry, Extensions as QuickaccessExtensions } from 'vs/platform/quickinput/common/quickAccess';
import { AbstractGotoSymbolQuickAccessProvider, IGotoSymbolQuickPickItem } from 'vs/editor/contrib/quickAccess/gotoSymbolQuickAccess';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkbenchEditorConfiguration, IEditorPane } from 'vs/workbench/common/editor';
import { IWorkbenchEditorConfiguration, IEditorPane, IVisibleEditorPane } from 'vs/workbench/common/editor';
import { ITextModel } from 'vs/editor/common/model';
import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { timeout } from 'vs/base/common/async';
......@@ -108,11 +108,13 @@ export class GotoSymbolQuickAccessProvider extends AbstractGotoSymbolQuickAccess
protected provideWithoutTextEditor(picker: IQuickPick<IGotoSymbolQuickPickItem>): IDisposable {
const pane = this.editorService.activeEditorPane;
if (!pane || !TableOfContentsProviderRegistry.has(pane.getId())) {
//
return super.provideWithoutTextEditor(picker);
if (pane && TableOfContentsProviderRegistry.has(pane.getId())) {
return this.doGetTableOfContentsPicks(picker, pane);
}
return super.provideWithoutTextEditor(picker);
}
private doGetTableOfContentsPicks(picker: IQuickPick<IGotoSymbolQuickPickItem>, pane: IVisibleEditorPane): IDisposable {
const provider = TableOfContentsProviderRegistry.get(pane.getId())!;
const cts = new CancellationTokenSource();
......@@ -144,7 +146,7 @@ export class GotoSymbolQuickAccessProvider extends AbstractGotoSymbolQuickAccess
disposables.add(picker.onDidAccept(() => {
picker.hide();
const [entry] = picker.selectedItems;
entries[entry.index]?.reveal();
entries[entry.index]?.pick();
}));
const updatePickerItems = () => {
......@@ -177,14 +179,11 @@ export class GotoSymbolQuickAccessProvider extends AbstractGotoSymbolQuickAccess
let ignoreFirstActiveEvent = true;
disposables.add(picker.onDidChangeActive(() => {
const [entry] = picker.activeItems;
if (entry && entries[entry.index]) {
if (ignoreFirstActiveEvent) {
ignoreFirstActiveEvent = false;
return;
if (!ignoreFirstActiveEvent) {
entries[entry.index]?.preview();
}
entries[entry.index]?.reveal();
ignoreFirstActiveEvent = false;
}
}));
......@@ -238,7 +237,8 @@ export interface ITableOfContentsEntry {
label: string;
detail?: string;
description?: string;
reveal(): any;
pick(): any;
preview(): any;
}
export interface ITableOfContentsProvider<T extends IEditorPane = IEditorPane> {
......
......@@ -14,7 +14,7 @@ TableOfContentsProviderRegistry.register(NotebookEditor.ID, new class implements
return undefined;
}
// return an entry per markdown header
const editorWidget = editor.getControl();
const notebookWidget = editor.getControl();
const result: ITableOfContentsEntry[] = [];
for (let cell of editor.viewModel.viewCells) {
const content = cell.getText();
......@@ -28,10 +28,14 @@ TableOfContentsProviderRegistry.register(NotebookEditor.ID, new class implements
result.push({
icon: cell.cellKind === CellKind.Markdown ? Codicon.markdown : Codicon.code,
label: matches[j].replace(/^[ \t]*(\#+)/, ''),
reveal: () => {
editorWidget.revealInCenterIfOutsideViewport(cell);
editorWidget.selectElement(cell);
// editor.focusNotebookCell(cell, 'container');
pick() {
notebookWidget.revealInCenterIfOutsideViewport(cell);
notebookWidget.selectElement(cell);
notebookWidget.focusNotebookCell(cell, 'container');
},
preview() {
notebookWidget.revealInCenterIfOutsideViewport(cell);
notebookWidget.selectElement(cell);
}
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册