@@ -75,22 +75,15 @@ define([
75
75
help : 'Run cells above' ,
76
76
help_index : 'xa' ,
77
77
handler : function ( ) {
78
- var mode = Jupyter . notebook . get_selected_cell ( ) . mode ;
79
- Jupyter . notebook . execute_cells_above ( ) ;
80
- Jupyter . notebook . select_next ( ) ;
81
- var type = Jupyter . notebook . get_selected_cell ( ) . cell_type ;
82
- if ( mode === "edit" && type === "code" ) Jupyter . notebook . edit_mode ( ) ;
78
+ execute_cells_above ( ) ;
83
79
return false ;
84
80
}
85
81
} ;
86
82
add_command_shortcuts [ params [ "run_cells_below" ] ] = {
87
83
help : 'Run cells below' ,
88
84
help_index : 'aa' ,
89
85
handler : function ( ) {
90
- var mode = Jupyter . notebook . get_selected_cell ( ) . mode ;
91
- Jupyter . notebook . execute_cells_below ( ) ;
92
- var type = Jupyter . notebook . get_selected_cell ( ) . cell_type ;
93
- if ( mode === "edit" && type === "code" ) Jupyter . notebook . edit_mode ( ) ;
86
+ execute_cells_below ( ) ;
94
87
return false ;
95
88
}
96
89
} ;
@@ -131,9 +124,7 @@ define([
131
124
help_index : 'ra' ,
132
125
handler : function ( ) {
133
126
var pos = Jupyter . notebook . element . scrollTop ( ) ;
134
- var ic = Jupyter . notebook . get_selected_index ( ) ;
135
- Jupyter . notebook . execute_all_cells ( ) ;
136
- Jupyter . notebook . select ( ic ) ;
127
+ execute_all_cells ( ) ;
137
128
Jupyter . notebook . element . animate ( {
138
129
scrollTop : pos
139
130
} , 100 ) ;
@@ -222,19 +213,40 @@ define([
222
213
for ( var i = 0 ; i < end ; i ++ ) {
223
214
if ( runcell === cells [ i ] ) {
224
215
if ( runcell . metadata . run_control !== undefined && runcell . metadata . run_control . marked === true ) {
225
- IPython . notebook . select ( i ) ;
226
216
var g = runcell . code_mirror . getGutterElement ( ) ;
227
217
$ ( g ) . css ( {
228
218
"background-color" : params . run_color
229
219
} ) ;
230
- IPython . notebook . execute_cell ( ) ;
220
+ runcell . execute ( ) ;
231
221
return ;
232
222
}
233
223
}
234
224
}
235
225
}
236
226
}
237
227
228
+ function _execute_without_selecting ( idx_start , idx_end , stop_on_error ) {
229
+ // notebook.execute_cells alters selection, this doesn't
230
+ var cells = Jupyter . notebook . get_cells ( ) ;
231
+ idx_start = idx_start !== undefined ? idx_start : 0 ;
232
+ idx_end = idx_end !== undefined ? idx_end : cells . length ;
233
+ for ( var ii = idx_start ; ii < idx_end ; ii ++ ) {
234
+ cells [ ii ] . execute ( stop_on_error ) ;
235
+ }
236
+ }
237
+
238
+ function execute_cells_above ( ) {
239
+ _execute_without_selecting ( 0 , Jupyter . notebook . get_selected_index ( ) ) ;
240
+ }
241
+
242
+ function execute_cells_below ( ) {
243
+ _execute_without_selecting ( Jupyter . notebook . get_selected_index ( ) , undefined ) ;
244
+ }
245
+
246
+ function execute_all_cells ( stop_on_error ) {
247
+ _execute_without_selecting ( 0 , undefined , stop_on_error ) ;
248
+ }
249
+
238
250
/**
239
251
* Run code cells marked in metadata
240
252
*
@@ -413,11 +425,7 @@ define([
413
425
*
414
426
*/
415
427
var run_all_cells_ignore_errors = function ( ) {
416
- var cells = Jupyter . notebook . get_cells ( ) ;
417
- var ncells = cells . length ;
418
- for ( var i = 0 ; i < ncells ; i ++ ) {
419
- cells [ i ] . execute ( false ) ;
420
- }
428
+ execute_all_cells ( false ) ;
421
429
} ;
422
430
423
431
/**
@@ -467,8 +475,9 @@ define([
467
475
'position' : 'absolute'
468
476
} ) ;
469
477
$ ( '#run_c' ) . on ( 'click' , function ( e ) {
470
- Jupyter . notebook . execute_cell ( ) ;
471
- e . target . blur ( )
478
+ var idx = Jupyter . notebook . get_selected_index ( ) ;
479
+ _execute_without_selecting ( idx , idx + 1 ) ;
480
+ e . target . blur ( ) ;
472
481
} )
473
482
. tooltip ( {
474
483
delay : {
@@ -477,9 +486,8 @@ define([
477
486
}
478
487
} ) ;
479
488
$ ( '#run_ca' ) . on ( 'click' , function ( e ) {
480
- Jupyter . notebook . execute_cells_above ( ) ;
481
- Jupyter . notebook . select_next ( ) ;
482
- e . target . blur ( )
489
+ execute_cells_above ( ) ;
490
+ e . target . blur ( ) ;
483
491
} )
484
492
. tooltip ( {
485
493
delay : {
@@ -488,8 +496,8 @@ define([
488
496
}
489
497
} ) ;
490
498
$ ( '#run_cb' ) . on ( 'click' , function ( e ) {
491
- Jupyter . notebook . execute_cells_below ( ) ;
492
- e . target . blur ( )
499
+ execute_cells_below ( ) ;
500
+ e . target . blur ( ) ;
493
501
} )
494
502
. tooltip ( {
495
503
delay : {
@@ -498,8 +506,8 @@ define([
498
506
}
499
507
} ) ;
500
508
$ ( '#run_a' ) . on ( 'click' , function ( e ) {
501
- Jupyter . notebook . execute_all_cells ( ) ;
502
- e . target . blur ( )
509
+ execute_all_cells ( ) ;
510
+ e . target . blur ( ) ;
503
511
} )
504
512
. tooltip ( {
505
513
delay : {
0 commit comments