@@ -12,17 +12,13 @@ import {
12
12
IToolbarWidgetRegistry
13
13
} from '@jupyterlab/apputils' ;
14
14
15
- import { CodeCell } from '@jupyterlab/cells' ;
15
+ import { Cell , CodeCell } from '@jupyterlab/cells' ;
16
16
17
17
import { Text , Time } from '@jupyterlab/coreutils' ;
18
18
19
19
import { IDocumentManager } from '@jupyterlab/docmanager' ;
20
20
21
- import {
22
- NotebookPanel ,
23
- INotebookTracker ,
24
- NotebookActions
25
- } from '@jupyterlab/notebook' ;
21
+ import { NotebookPanel , INotebookTracker } from '@jupyterlab/notebook' ;
26
22
27
23
import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
28
24
@@ -284,21 +280,29 @@ const scrollOutput: JupyterFrontEndPlugin<void> = {
284
280
cell . toggleClass ( SCROLLED_OUTPUTS_CLASS , scroll ) ;
285
281
} ;
286
282
287
- NotebookActions . executed . connect ( ( sender , change ) => {
288
- const { cell } = change ;
283
+ const handlers : { [ id : string ] : ( ) => void } = { } ;
284
+
285
+ const setAutoScroll = ( cell : Cell ) => {
289
286
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 ] ) ;
291
295
}
292
- } ) ;
296
+ } ;
293
297
294
298
tracker . widgetAdded . connect ( ( sender , notebook ) => {
295
299
// when the notebook widget is created, process all the cells
296
300
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 ) ;
302
306
} ) ;
303
307
} ) ;
304
308
0 commit comments