Skip to content

Commit c529ed9

Browse files
committed
Fix autoscroll logic
1 parent b475821 commit c529ed9

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

packages/notebook-extension/src/index.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@ import {
1212
IToolbarWidgetRegistry
1313
} from '@jupyterlab/apputils';
1414

15-
import { CodeCell } from '@jupyterlab/cells';
15+
import { Cell, CodeCell } from '@jupyterlab/cells';
1616

1717
import { Text, Time } from '@jupyterlab/coreutils';
1818

1919
import { IDocumentManager } from '@jupyterlab/docmanager';
2020

21-
import {
22-
NotebookPanel,
23-
INotebookTracker,
24-
NotebookActions
25-
} from '@jupyterlab/notebook';
21+
import { NotebookPanel, INotebookTracker } from '@jupyterlab/notebook';
2622

2723
import { ISettingRegistry } from '@jupyterlab/settingregistry';
2824

@@ -284,21 +280,29 @@ const scrollOutput: JupyterFrontEndPlugin<void> = {
284280
cell.toggleClass(SCROLLED_OUTPUTS_CLASS, scroll);
285281
};
286282

287-
NotebookActions.executed.connect((sender, change) => {
288-
const { cell } = change;
283+
const handlers: { [id: string]: () => void } = {};
284+
285+
const setAutoScroll = (cell: Cell) => {
289286
if (cell.model.type === 'code') {
290-
autoScroll(cell as CodeCell);
287+
const codeCell = cell as CodeCell;
288+
const id = codeCell.model.id;
289+
autoScroll(codeCell);
290+
if (handlers[id]) {
291+
codeCell.outputArea.model.changed.disconnect(handlers[id]);
292+
}
293+
handlers[id] = () => autoScroll(codeCell);
294+
codeCell.outputArea.model.changed.connect(handlers[id]);
291295
}
292-
});
296+
};
293297

294298
tracker.widgetAdded.connect((sender, notebook) => {
295299
// when the notebook widget is created, process all the cells
296300
notebook.sessionContext.ready.then(() => {
297-
notebook.content.widgets.forEach(cell => {
298-
if (cell.model.type === 'code') {
299-
autoScroll(cell as CodeCell);
300-
}
301-
});
301+
notebook.content.widgets.forEach(setAutoScroll);
302+
});
303+
304+
notebook.model?.cells.changed.connect((sender, args) => {
305+
notebook.content.widgets.forEach(setAutoScroll);
302306
});
303307
});
304308

0 commit comments

Comments
 (0)