From c2c74e602df2cb91015c00477f484411b998624a Mon Sep 17 00:00:00 2001 From: rebornix Date: Fri, 27 Mar 2020 14:50:00 -0700 Subject: [PATCH] reveal active line into view only when it is not triggered by view restore. --- .../notebook/browser/view/renderers/codeCell.ts | 7 ++++++- .../notebook/browser/view/renderers/markdownCell.ts | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts index 23dbf910225..a54010e4550 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts @@ -130,7 +130,12 @@ export class CodeCell extends Disposable { } })); - this._register(templateData.editor!.onDidChangeCursorSelection(() => { + this._register(templateData.editor!.onDidChangeCursorSelection((e) => { + if (e.source === 'restoreState') { + // do not reveal the cell into view if this selection change was caused by restoring editors... + return; + } + const primarySelection = templateData.editor!.getSelection(); if (primarySelection) { 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 5501828c929..a4ba18a9979 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts @@ -180,6 +180,19 @@ export class StatefullMarkdownCell extends Disposable { } })); + this.localDisposables.add(this.editor!.onDidChangeCursorSelection((e) => { + if (e.source === 'restoreState') { + // do not reveal the cell into view if this selection change was caused by restoring editors... + return; + } + + const primarySelection = this.editor!.getSelection(); + + if (primarySelection) { + this.notebookEditor.revealLineInView(this.viewCell, primarySelection!.positionLineNumber); + } + })); + let cellWidthResizeObserver = getResizesObserver(this.templateData.editingContainer!, dimension, () => { let newWidth = cellWidthResizeObserver.getWidth(); let realContentHeight = this.editor!.getContentHeight();