Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start new notebooks in edit mode #7666

Merged
merged 3 commits into from Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -63,7 +63,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