@@ -29,7 +29,8 @@ import {
29
29
} from '@jupyterlab/toc' ;
30
30
import { ITranslator } from '@jupyterlab/translation' ;
31
31
import { tocIcon } from '@jupyterlab/ui-components' ;
32
- import { runNestedCodeCells } from '@jupyterlab/toc' ;
32
+ import { INotebookHeading } from '@jupyterlab/toc' ;
33
+ import { CodeCell , MarkdownCell } from '@jupyterlab/cells' ;
33
34
34
35
/**
35
36
* The command IDs used by TOC item.
@@ -88,7 +89,34 @@ async function activateTOC(
88
89
89
90
app . commands . addCommand ( CommandIDs . runCells , {
90
91
execute : args => {
91
- return runNestedCodeCells ( toc . headings , toc . activeEntry ) ;
92
+ const panel = notebookTracker . currentWidget ;
93
+ if ( panel == null ) {
94
+ return ;
95
+ }
96
+
97
+ const cells = panel . content . widgets ;
98
+ if ( cells === undefined ) {
99
+ return ;
100
+ }
101
+
102
+ const activeCell = ( toc . activeEntry as INotebookHeading ) . cellRef ;
103
+
104
+ if ( activeCell instanceof MarkdownCell ) {
105
+ let level = activeCell . headingInfo . level ;
106
+ for ( let i = cells . indexOf ( activeCell ) + 1 ; i < cells . length ; i ++ ) {
107
+ const cell = cells [ i ] ;
108
+ if ( cell instanceof MarkdownCell && cell . headingInfo . level <= level ) {
109
+ break ;
110
+ }
111
+ if ( cell instanceof CodeCell ) {
112
+ void CodeCell . execute ( cell , panel . sessionContext ) ;
113
+ }
114
+ }
115
+ } else {
116
+ if ( activeCell instanceof CodeCell ) {
117
+ void CodeCell . execute ( activeCell , panel . sessionContext ) ;
118
+ }
119
+ }
92
120
} ,
93
121
label : trans . __ ( 'Run Cell(s)' )
94
122
} ) ;
0 commit comments