提交 ae6e90c4 编写于 作者: J Johannes Rieken

restore view state when canceling notebook quick outline,...

restore view state when canceling notebook quick outline, https://github.com/microsoft/vscode/issues/96489
上级 fa96b9c8
......@@ -137,7 +137,7 @@ export class GotoSymbolQuickAccessProvider extends AbstractGotoSymbolQuickAccess
picker.busy = true;
provider.provideTableOfContents(pane, cts.token).then(entries => {
provider.provideTableOfContents(pane, { disposables }, cts.token).then(entries => {
picker.busy = false;
......@@ -256,7 +256,8 @@ export interface ITableOfContentsEntry {
}
export interface ITableOfContentsProvider<T extends IEditorPane = IEditorPane> {
provideTableOfContents(editor: T, token: CancellationToken): Promise<ITableOfContentsEntry[] | undefined | null>;
provideTableOfContents(editor: T, context: { disposables: DisposableStore }, token: CancellationToken): Promise<ITableOfContentsEntry[] | undefined | null>;
}
class ProviderRegistry {
......
......@@ -7,14 +7,28 @@ import { TableOfContentsProviderRegistry, ITableOfContentsProvider, ITableOfCont
import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEditor';
import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { Codicon } from 'vs/base/common/codicons';
import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
TableOfContentsProviderRegistry.register(NotebookEditor.ID, new class implements ITableOfContentsProvider {
async provideTableOfContents(editor: NotebookEditor) {
async provideTableOfContents(editor: NotebookEditor, context: { disposables: DisposableStore }) {
if (!editor.viewModel) {
return undefined;
}
// return an entry per markdown header
const notebookWidget = editor.getControl();
if (!notebookWidget) {
return undefined;
}
// restore initial view state when no item was picked
let didPickOne = false;
const viewState = notebookWidget.getEditorViewState();
context.disposables.add(toDisposable(() => {
if (!didPickOne) {
notebookWidget.restoreListViewState(viewState);
}
}));
const result: ITableOfContentsEntry[] = [];
for (const cell of editor.viewModel.viewCells) {
const content = cell.getText();
......@@ -29,13 +43,14 @@ TableOfContentsProviderRegistry.register(NotebookEditor.ID, new class implements
icon: cell.cellKind === CellKind.Markdown ? Codicon.markdown : Codicon.code,
label: matches[j].replace(/^[ \t]*(\#+)/, ''),
pick() {
notebookWidget?.revealInCenterIfOutsideViewport(cell);
notebookWidget?.selectElement(cell);
notebookWidget?.focusNotebookCell(cell, cell.cellKind === CellKind.Markdown ? 'container' : 'editor');
didPickOne = true;
notebookWidget.revealInCenterIfOutsideViewport(cell);
notebookWidget.selectElement(cell);
notebookWidget.focusNotebookCell(cell, cell.cellKind === CellKind.Markdown ? 'container' : 'editor');
},
preview() {
notebookWidget?.revealInCenterIfOutsideViewport(cell);
notebookWidget?.selectElement(cell);
notebookWidget.revealInCenterIfOutsideViewport(cell);
notebookWidget.selectElement(cell);
}
});
}
......
......@@ -395,7 +395,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
this._detachModel();
await this._attachModel(textModel, viewState);
} else {
this._restoreListViewState(viewState);
this.restoreListViewState(viewState);
}
// clear state
......@@ -632,10 +632,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
this._dndController?.clearGlobalDragState();
// restore list state at last, it must be after list layout
this._restoreListViewState(viewState);
this.restoreListViewState(viewState);
}
private _restoreListViewState(viewState: INotebookEditorViewState | undefined): void {
restoreListViewState(viewState: INotebookEditorViewState | undefined): void {
if (viewState?.scrollPosition !== undefined) {
this._list!.scrollTop = viewState!.scrollPosition.top;
this._list!.scrollLeft = viewState!.scrollPosition.left;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册