Skip to content

Commit

Permalink
Always create a model with an empty cell
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Silvester committed Dec 20, 2019
1 parent b54f4e6 commit 01493cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/notebook/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ export class NotebookModel extends DocumentModel implements INotebookModel {
*/
initialize(): void {
super.initialize();
if (!this.cells.length) {
let factory = this.contentFactory;
this.cells.push(factory.createCodeCell({}));
}
this.cells.clearUndo();
}

Expand Down
11 changes: 5 additions & 6 deletions packages/notebook/src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ export class NotebookPanel extends DocumentWidget<Notebook, INotebookModel> {
return;
}

// If the notebook model is empty (new file), set it to edit mode.
if (this.content.model.cells.length === 0) {
// Wait for an animation frame so the spinner is hidden and the
// widget can be focused.
requestAnimationFrame(() => {
// Set the document edit mode on initial open if it looks like a new document.
if (this.content.widgets.length === 1) {
let cellModel = this.content.widgets[0].model;
if (cellModel.type === 'code' && cellModel.value.text === '') {
this.content.mode = 'edit';
});
}
}
});
}
Expand Down

0 comments on commit 01493cd

Please sign in to comment.