diff --git a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts index 4e044641bf2d0e310ce1aca30b2aaa6b18d8488a..7e6b84fc447762381f2f5b2b254fefc25c01c9f9 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts @@ -106,7 +106,7 @@ export class NotebookCellList extends WorkbenchList { } if (revealType === CellRevealType.Range) { - element.revealRange(range); + element.revealRangeInCenter(range); } } @@ -162,7 +162,7 @@ export class NotebookCellList extends WorkbenchList { this.view.setScrollTop(lineOffsetInView - this.view.renderHeight / 2); if (revealType === CellRevealType.Range) { - element.revealRange(range); + element.revealRangeInCenter(range); } }; @@ -194,7 +194,7 @@ export class NotebookCellList extends WorkbenchList { this.view.setScrollTop(lineOffsetInView - this.view.renderHeight / 2); if (revealType === CellRevealType.Range) { - element.revealRange(range); + element.revealRangeInCenter(range); } }; @@ -202,15 +202,17 @@ export class NotebookCellList extends WorkbenchList { const wrapperBottom = scrollTop + this.view.renderHeight; const elementTop = this.view.elementTop(index); const viewItemOffset = elementTop; + const element = this.view.element(index); if (viewItemOffset < scrollTop || viewItemOffset > wrapperBottom) { this.view.setScrollTop(viewItemOffset - this.view.renderHeight / 2); - const element = this.view.element(index); if (!element.editorAttached) { getEditorAttachedPromise(element).then(() => reveal(index, range, revealType)); } else { // should not happen } + } else { + element.revealRangeInCenter(range); } } diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts index 4c3d9587135d0f3af7ce2901253337b445d6e0d8..a8a8ab08a38fa30f45116ac71312b9700b8932d8 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts @@ -68,6 +68,7 @@ export class StatefullMarkdownCell extends Disposable { } }, {}); + viewCell.attachTextEditor(this.editor); const cts = new CancellationTokenSource(); this._register({ dispose() { cts.dispose(true); } }); diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel.ts index 6395c009ee51b68a00475128d16d2780d94b29ef..1b8cc5e70ebb0903a54892e87f32f8f8a848212f 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel.ts @@ -291,8 +291,8 @@ export class CellViewModel extends Disposable { this._onDidChangeEditorAttachState.fire(false); } - revealRange(range: Range) { - this._textEditor?.revealRange(range); + revealRangeInCenter(range: Range) { + this._textEditor?.revealRangeInCenter(range); } getLineScrollTopOffset(line: number): number { diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts index 45190a662dd08a5be26756ddacfb6928a2e6b668..8bfae55b3d1304cbcc6573fc8e636c397f5005f0 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts @@ -190,7 +190,9 @@ export class NotebookViewModel extends Disposable { if (!mapping.has(ownerId)) { const cell = this.viewCells.find(cell => cell.handle === ownerId); - mapping.set(ownerId, { cell: cell!, oldDecorations: [], newDecorations: [] }); + if (cell) { + mapping.set(ownerId, { cell: cell, oldDecorations: [], newDecorations: [] }); + } } const data = mapping.get(ownerId)!; @@ -202,7 +204,10 @@ export class NotebookViewModel extends Disposable { if (!mapping.has(ownerId)) { const cell = this.viewCells.find(cell => cell.handle === ownerId); - mapping.set(ownerId, { cell: cell!, oldDecorations: [], newDecorations: [] }); + + if (cell) { + mapping.set(ownerId, { cell: cell, oldDecorations: [], newDecorations: [] }); + } } const data = mapping.get(ownerId)!;