Skip to content

Commit

Permalink
Merge pull request #7666 from blink1073/notebook-edit-mode
Browse files Browse the repository at this point in the history
Start new notebooks in edit mode
  • Loading branch information
jasongrout committed Dec 23, 2019
2 parents 8950e78 + 188bff1 commit 5df09d7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/notebook/src/model.ts
Expand Up @@ -282,9 +282,17 @@ export class NotebookModel extends DocumentModel implements INotebookModel {

/**
* Initialize the model with its current state.
*
* # Notes
* Adds an empty code cell if the model is empty
* and clears undo state.
*/
initialize(): void {
super.initialize();
if (!this.cells.length) {
let factory = this.contentFactory;
this.cells.push(factory.createCodeCell({}));
}
this.cells.clearUndo();
}

Expand Down
1 change: 0 additions & 1 deletion packages/notebook/src/panel.ts
Expand Up @@ -66,7 +66,6 @@ export class NotebookPanel extends DocumentWidget<Notebook, INotebookModel> {
this
);
this.context.saveState.connect(this._onSave, this);

void this.revealed.then(() => {
if (this.isDisposed) {
// this widget has already been disposed, bail
Expand Down
20 changes: 20 additions & 0 deletions tests/test-notebook/src/model.spec.ts
Expand Up @@ -345,6 +345,26 @@ describe('@jupyterlab/notebook', () => {
});
});

describe('#initialize()', () => {
it('should add one code cell if the model is empty', () => {
const model = new NotebookModel();
expect(model.cells.length).to.equal(0);
model.initialize();
expect(model.cells.length).to.equal(1);
expect(model.cells.get(0).type).to.equal('code');
});

it('should clear undo state', () => {
const model = new NotebookModel();
const cell = model.contentFactory.createCodeCell({});
cell.value.text = 'foo';
model.cells.push(cell);
expect(model.cells.canUndo).to.equal(true);
model.initialize();
expect(model.cells.canUndo).to.equal(false);
});
});

describe('.ContentFactory', () => {
let factory = new NotebookModel.ContentFactory({});

Expand Down

0 comments on commit 5df09d7

Please sign in to comment.