Add new cells after the current one when adding a cell from the notebook toolbar. (#19649)

This commit is contained in:
Cory Rivera
2022-06-07 10:12:15 -07:00
committed by GitHub
parent 8c223f503e
commit 7007e18314

View File

@@ -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 });
}