Skip to content

Commit

Permalink
Restore side effects of runAll()
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Aug 21, 2023
1 parent eea7612 commit 62bd31f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/notebook/src/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ export namespace NotebookActions {
* @param translator - The application translator.
*
* #### Notes
* The existing selection will be preserved.
* The mode will be changed to command.
* An execution error will prevent the remaining code cells from executing.
* All markdown cells will be rendered.
*/
Expand Down Expand Up @@ -728,6 +730,7 @@ export namespace NotebookActions {
}

const state = Private.getState(notebook);
const lastIndex = notebook.widgets.length;

const promise = Private.runCells(
notebook,
Expand All @@ -737,6 +740,9 @@ export namespace NotebookActions {
translator
);

notebook.activeCellIndex = lastIndex;
notebook.deselectAll();

Private.handleRunState(notebook, state, true);
return promise;
}
Expand Down Expand Up @@ -800,6 +806,8 @@ export namespace NotebookActions {
translator
);

notebook.deselectAll();

Private.handleRunState(notebook, state, true);
return promise;
}
Expand Down Expand Up @@ -2223,6 +2231,8 @@ namespace Private {
translator?: ITranslator
): Promise<boolean> {
const lastCell = cells[-1];
notebook.mode = 'command';

return Promise.all(
cells.map(cell =>
runCell(notebook, cell, sessionContext, sessionDialogs, translator)
Expand Down
30 changes: 30 additions & 0 deletions packages/notebook/test/actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,36 @@ describe('@jupyterlab/notebook', () => {
});
});

describe('#runCells()', () => {
beforeEach(() => {
// Make sure all cells have valid code.
widget.widgets[2].model.sharedModel.setSource('a = 1');
});

it('should change to command mode', async () => {
widget.mode = 'edit';
const result = await NotebookActions.runCells(
widget,
[widget.widgets[2]],
sessionContext
);
expect(result).toBe(true);
expect(widget.mode).toBe('command');
});

it('should preserve the existing selection', async () => {
const next = widget.widgets[2];
widget.select(next);
const result = await NotebookActions.runCells(
widget,
[widget.widgets[1]],
sessionContext
);
expect(result).toBe(true);
expect(widget.isSelected(widget.widgets[2])).toBe(true);
});
});

describe('#runAll()', () => {
beforeEach(() => {
// Make sure all cells have valid code.
Expand Down

0 comments on commit 62bd31f

Please sign in to comment.