From 7007e1831434c0fc37dc50ab4f3da093b93518b1 Mon Sep 17 00:00:00 2001 From: Cory Rivera Date: Tue, 7 Jun 2022 10:12:15 -0700 Subject: [PATCH] Add new cells after the current one when adding a cell from the notebook toolbar. (#19649) --- .../workbench/contrib/notebook/browser/notebookActions.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/browser/notebookActions.ts b/src/sql/workbench/contrib/notebook/browser/notebookActions.ts index e6c64290d0..dbfc43df4e 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebookActions.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebookActions.ts @@ -80,9 +80,12 @@ export class AddCellAction extends Action { context.model.sendNotebookTelemetryActionEvent(TelemetryKeys.NbTelemetryAction.AddCell, { cell_type: this.cellType }); } } else { - //Add Cell after current selected cell. + // Add cell after currently selected cell, or at the end of the notebook if no cell is selected const editor = this._notebookService.findNotebookEditor(context); - const index = editor.cells?.findIndex(cell => cell.active) ?? 0; + if (editor.cells) { + let currentCellIndex = editor.cells.findIndex(cell => cell.active); + index = currentCellIndex !== -1 ? currentCellIndex + 1 : editor.cells.length; + } editor.addCell(this.cellType, index); editor.model.sendNotebookTelemetryActionEvent(TelemetryKeys.NbTelemetryAction.AddCell, { cell_type: this.cellType }); }