diff --git a/src/vs/workbench/browser/parts/editor/breadcrumbsModel.ts b/src/vs/workbench/browser/parts/editor/breadcrumbsModel.ts index a20b070c6460cec1183df7145ad21a80007232e5..9c4fdfa2c6d7617033c8dd0ec537cee87b30bcb8 100644 --- a/src/vs/workbench/browser/parts/editor/breadcrumbsModel.ts +++ b/src/vs/workbench/browser/parts/editor/breadcrumbsModel.ts @@ -165,7 +165,6 @@ export class BreadcrumbsModel { if (outline) { this._outlineDisposables.add(outline); this._outlineDisposables.add(outline.onDidChange(() => this._onDidUpdate.fire(this))); - this._outlineDisposables.add(outline.onDidChangeActiveEntry(() => this._onDidUpdate.fire(this))); } }).catch(err => { diff --git a/src/vs/workbench/contrib/codeEditor/browser/outline/documentSymbolsOutline.ts b/src/vs/workbench/contrib/codeEditor/browser/outline/documentSymbolsOutline.ts index 96d53499f0d4d2d8fa23e57750d58b1a44c44077..c781c58957f4e24de346aac6a8140c6cc33736ec 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/outline/documentSymbolsOutline.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/outline/documentSymbolsOutline.ts @@ -38,9 +38,6 @@ class DocumentSymbolsOutline implements IOutline { private readonly _onDidChange = new Emitter(); readonly onDidChange: Event = this._onDidChange.event; - private readonly _onDidChangeActiveEntry = new Emitter(); - readonly onDidChangeActiveEntry: Event = this._onDidChangeActiveEntry.event; - private _outlineModel?: OutlineModel; private _outlineElementChain: Array = []; private _outlineDisposables = new DisposableStore(); diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebooksOutline.ts b/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebooksOutline.ts index e0dffd5db6f27333456dad13f1a8c5539013b70b..f7e267c59cbcda4576e2affcdec43eb6f7ba1c07 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebooksOutline.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebooksOutline.ts @@ -99,11 +99,8 @@ class NotebookCellOutline implements IOutline { private readonly _onDidChange = new Emitter(); readonly onDidChange: Event = this._onDidChange.event; - private readonly _onDidChangeActiveEntry = new Emitter(); - readonly onDidChangeActiveEntry: Event = this._onDidChangeActiveEntry.event; - - private _activeEntry?: OutlineEntry; private _entries: OutlineEntry[] = []; + private _activeEntry: number = -1; private readonly _entriesDisposables = new DisposableStore(); readonly config: OutlineTreeConfiguration; @@ -119,26 +116,23 @@ class NotebookCellOutline implements IOutline { selectionListener.clear(); } else { selectionListener.value = combinedDisposable( - _editor.viewModel.onDidChangeSelection(() => this._computeActive()), + _editor.viewModel.onDidChangeSelection(() => this._recomputeActive()), _editor.viewModel.onDidChangeViewCells(() => { - this._computeEntries(); - this._computeActive(); + this._recomputeState(); })); } }; this._dispoables.add(_editor.onDidChangeModel(() => { - this._computeEntries(); - this._computeActive(); + this._recomputeState(); installSelectionListener(); })); - this._computeEntries(); - this._computeActive(); + this._recomputeState(); installSelectionListener(); this.config = new OutlineTreeConfiguration( - { getBreadcrumbElements: () => this._activeEntry ? Iterable.single(this._activeEntry) : Iterable.empty() }, + { getBreadcrumbElements: () => this._activeEntry >= 0 ? Iterable.single(this._entries[this._activeEntry]) : Iterable.empty() }, { getQuickPickElements: () => this._entries.map(entry => ({ element: entry, label: `$(${entry.icon.id}) ${entry.label}`, ariaLabel: entry.label })) }, { getChildren: parent => parent === this ? this._entries : [] }, new NotebookOutlineVirtualDelegate(), @@ -158,15 +152,18 @@ class NotebookCellOutline implements IOutline { this._dispoables.dispose(); } - // TODO@jrieken recompute entries on demand, not eagerly - private _computeEntries(): void { + private _recomputeState(): void { this._entriesDisposables.clear(); + this._activeEntry = -1; this._entries.length = 0; const { viewModel } = this._editor; if (!viewModel) { return; } + + const [selected] = viewModel.selectionHandles; + for (const cell of viewModel.viewCells) { const content = cell.getText(); const regexp = cell.cellKind === CellKind.Markdown @@ -176,35 +173,36 @@ class NotebookCellOutline implements IOutline { const matches = content.match(regexp); if (matches && matches.length) { for (let j = 0; j < matches.length; j++) { - this._entries.push(new OutlineEntry( + const newLen = this._entries.push(new OutlineEntry( cell, matches[j].replace(/^[ \t]*(\#+)/, '').trim(), cell.cellKind === CellKind.Markdown ? Codicon.markdown : Codicon.code )); + if (cell.handle === selected) { + this._activeEntry = newLen - 1; + } } } // send an event whenever any of the cells change this._entriesDisposables.add(cell.model.onDidChangeContent(() => { - this._computeEntries(); - this._computeActive(); + this._recomputeState(); this._onDidChange.fire(this); })); } this._onDidChange.fire(this); } - private _computeActive(): void { - let newActive: OutlineEntry | undefined; - if (this._editor.viewModel) { - const [first] = this._editor.viewModel.selectionHandles; - newActive = typeof first === 'number' - ? this._entries.find(candidate => candidate.cell.handle === first) - : undefined; + private _recomputeActive(): void { + let newIdx = -1; + const { viewModel } = this._editor; + if (viewModel) { + const [selected] = viewModel.selectionHandles; + newIdx = this._entries.findIndex(entry => entry.cell.handle === selected); } - if (this._activeEntry !== newActive) { - this._activeEntry = newActive; - this._onDidChangeActiveEntry.fire(this); + if (newIdx !== this._activeEntry) { + this._activeEntry = newIdx; + this._onDidChange.fire(this); } } diff --git a/src/vs/workbench/services/outline/browser/outline.ts b/src/vs/workbench/services/outline/browser/outline.ts index ab585074474504567221dd5c7d9875affaa89bb1..755eac4e2550bb0c02111f6c3196057b866e5d97 100644 --- a/src/vs/workbench/services/outline/browser/outline.ts +++ b/src/vs/workbench/services/outline/browser/outline.ts @@ -62,7 +62,6 @@ export interface IOutline { readonly config: OutlineTreeConfiguration readonly onDidChange: Event; - readonly onDidChangeActiveEntry: Event readonly isEmpty: boolean;