From 397175e067bc7e80cd41af45da5fcd6f322e51f2 Mon Sep 17 00:00:00 2001 From: Aaron Munger Date: Fri, 26 May 2023 14:30:46 -0700 Subject: [PATCH] minimum scrolling to reveal the next cell on shift+enter (#183600) do minimum scrolling to reveal the next cell on Execute cell and select next --- .../contrib/notebook/browser/controller/executeActions.ts | 8 ++++---- .../workbench/contrib/notebook/browser/notebookBrowser.ts | 1 + .../contrib/notebook/browser/notebookEditorWidget.ts | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts b/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts index dece7cb2061..3583f8f8a30 100644 --- a/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts @@ -456,12 +456,12 @@ registerAction2(class ExecuteCellSelectBelow extends NotebookCellAction { const nextCell = context.notebookEditor.cellAt(idx + 1); context.cell.updateEditState(CellEditState.Preview, EXECUTE_CELL_SELECT_BELOW); if (nextCell) { - await context.notebookEditor.focusNotebookCell(nextCell, 'container'); + await context.notebookEditor.focusNotebookCell(nextCell, 'container', { minimalScrolling: true }); } else { const newCell = insertCell(languageService, context.notebookEditor, idx, CellKind.Markup, 'below'); if (newCell) { - await context.notebookEditor.focusNotebookCell(newCell, 'editor'); + await context.notebookEditor.focusNotebookCell(newCell, 'editor', { minimalScrolling: true }); } } return; @@ -469,12 +469,12 @@ registerAction2(class ExecuteCellSelectBelow extends NotebookCellAction { // Try to select below, fall back on inserting const nextCell = context.notebookEditor.cellAt(idx + 1); if (nextCell) { - await context.notebookEditor.focusNotebookCell(nextCell, 'container'); + await context.notebookEditor.focusNotebookCell(nextCell, 'container', { minimalScrolling: true }); } else { const newCell = insertCell(languageService, context.notebookEditor, idx, CellKind.Code, 'below'); if (newCell) { - await context.notebookEditor.focusNotebookCell(newCell, 'editor'); + await context.notebookEditor.focusNotebookCell(newCell, 'editor', { minimalScrolling: true }); } } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts index 4f133952ef3..a58d4ebd9b0 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts @@ -150,6 +150,7 @@ export interface ICommonCellInfo { export interface IFocusNotebookCellOptions { readonly skipReveal?: boolean; readonly focusEditorLine?: number; + readonly minimalScrolling?: boolean; } //#endregion diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index ef205149872..87d4f5528b9 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -2352,6 +2352,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD if (typeof options?.focusEditorLine === 'number') { this._cursorNavMode.set(true); this.revealInView(cell); + } else if (options?.minimalScrolling) { + this.revealInView(cell); } else { this.revealInCenterIfOutsideViewport(cell); }