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