Run and Add Cell keybinding support (#3896)

- As part of this, fixed bug in the insertCell API where it didn't add to the end / failed if no cells existed
This commit is contained in:
Kevin Cunnane
2019-02-04 14:02:15 -08:00
committed by GitHub
parent 15929e8cf2
commit 2fce771214
12 changed files with 185 additions and 34 deletions

View File

@@ -286,11 +286,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
index = undefined;
}
// Set newly created cell as active cell
if (this._activeCell) {
this._activeCell.active = false;
}
this._activeCell = cell;
this._activeCell.active = true;
this.updateActiveCell(cell);
this._contentChangedEmitter.fire({
changeType: NotebookChangeType.CellsAdded,
@@ -301,6 +297,14 @@ export class NotebookModel extends Disposable implements INotebookModel {
return cell;
}
private updateActiveCell(cell: ICellModel) {
if (this._activeCell) {
this._activeCell.active = false;
}
this._activeCell = cell;
this._activeCell.active = true;
}
private createCell(cellType: CellType): ICellModel {
let singleCell: nb.ICellContents = {
cell_type: cellType,
@@ -341,6 +345,9 @@ export class NotebookModel extends Disposable implements INotebookModel {
newCells.push(this.notebookOptions.factory.createCell(contents, { notebook: this, isTrusted: this._trustedMode }));
}
this._cells.splice(edit.range.start, edit.range.end - edit.range.start, ...newCells);
if (newCells.length > 0) {
this.updateActiveCell(newCells[0]);
}
this._contentChangedEmitter.fire({
changeType: NotebookChangeType.CellsAdded
});