@@ -6,6 +6,24 @@ define([
6
6
] , function ( Jupyter , $ ) {
7
7
"use strict" ;
8
8
9
+ // define default values for config parameters
10
+ var params = {
11
+ toggle_enable_edit_shortcuts : true ,
12
+ toggle_enable_command_shortcuts : true ,
13
+ toggle_enable_esc_shortcut : true ,
14
+ toggle_enable_enter_shortcuts : true ,
15
+ } ;
16
+
17
+ // updates default params with any specified in the server's config
18
+ var update_params = function ( ) {
19
+ var config = Jupyter . notebook . config ;
20
+ for ( var key in params ) {
21
+ if ( config . data . hasOwnProperty ( key ) ) {
22
+ params [ key ] = config . data [ key ] ;
23
+ }
24
+ }
25
+ } ;
26
+
9
27
var add_command_shortcuts = {
10
28
'home' : {
11
29
help : 'Go to top' ,
@@ -81,7 +99,7 @@ define([
81
99
} ;
82
100
83
101
var add_edit_shortcuts = {
84
- 'alt-= ' : {
102
+ 'alt-subtract ' : {
85
103
help : 'Merge cell with previous cell' ,
86
104
help_index : 'eb' ,
87
105
handler : function ( ) {
@@ -93,28 +111,6 @@ define([
93
111
}
94
112
}
95
113
} ,
96
- 'shift-enter' : {
97
- help : 'Run cell and select next in edit mode' ,
98
- help_index : 'bb' ,
99
- handler : function ( ) {
100
- Jupyter . notebook . execute_cell_and_select_below ( ) ;
101
- var rendered = Jupyter . notebook . get_selected_cell ( ) . rendered ;
102
- var ccell = Jupyter . notebook . get_selected_cell ( ) . cell_type ;
103
- if ( rendered === false || ccell === 'code' ) Jupyter . notebook . edit_mode ( ) ;
104
- return false ;
105
- }
106
- } ,
107
- 'ctrl-enter' : {
108
- help : 'Run selected cell stay in edit mode' ,
109
- help_index : 'bb' ,
110
- handler : function ( ) {
111
- var cell = Jupyter . notebook . get_selected_cell ( ) ;
112
- var mode = cell . mode ;
113
- cell . execute ( ) ;
114
- if ( mode === "edit" ) Jupyter . notebook . edit_mode ( ) ;
115
- return false ;
116
- }
117
- } ,
118
114
'alt-n' : {
119
115
help : 'Toggle line numbers' ,
120
116
help_index : 'xy' ,
@@ -181,37 +177,92 @@ define([
181
177
}
182
178
} ;
183
179
180
+ var add_edit_enter_shortcuts = {
181
+ 'shift-enter' : {
182
+ help : 'Run cell and select next in edit mode' ,
183
+ help_index : 'bb' ,
184
+ handler : function ( ) {
185
+ Jupyter . notebook . execute_cell_and_select_below ( ) ;
186
+ var rendered = Jupyter . notebook . get_selected_cell ( ) . rendered ;
187
+ var ccell = Jupyter . notebook . get_selected_cell ( ) . cell_type ;
188
+ if ( rendered === false || ccell === 'code' ) Jupyter . notebook . edit_mode ( ) ;
189
+ return false ;
190
+ }
191
+ } ,
192
+ 'ctrl-enter' : {
193
+ help : 'Run selected cell stay in edit mode' ,
194
+ help_index : 'bb' ,
195
+ handler : function ( ) {
196
+ var cell = Jupyter . notebook . get_selected_cell ( ) ;
197
+ var mode = cell . mode ;
198
+ cell . execute ( ) ;
199
+ if ( mode === "edit" ) Jupyter . notebook . edit_mode ( ) ;
200
+ return false ;
201
+ }
202
+ }
203
+ } ;
184
204
185
- var load_ipython_extension = function ( ) {
205
+ var initialize = function ( ) {
206
+ // Update default parameters
207
+ update_params ( ) ;
208
+
186
209
var action ;
187
210
var prefix = 'navigation_hotkeys' ;
188
211
var action_name ;
189
212
var action_name_spaces ;
190
213
var action_full_name ;
191
214
192
- for ( var key in add_command_shortcuts ) {
193
- // check if the property/key is defined in the object itself, not in parent
194
- if ( add_command_shortcuts . hasOwnProperty ( key ) ) {
195
- action = add_command_shortcuts [ key ] ;
196
- action_name_spaces = add_command_shortcuts [ key ] [ 'help' ] ;
197
- action_name = action_name_spaces . replace ( / / g, "-" ) . toLowerCase ( ) ;
198
- action_full_name = Jupyter . keyboard_manager . actions . register ( action , action_name , prefix ) ;
199
- Jupyter . keyboard_manager . command_shortcuts . add_shortcut ( key , action_full_name ) ;
215
+ if ( params . toggle_enable_command_shortcuts ) {
216
+ for ( var key in add_command_shortcuts ) {
217
+ // check if the property/key is defined in the object itself, not in parent
218
+ if ( add_command_shortcuts . hasOwnProperty ( key ) ) {
219
+ action = add_command_shortcuts [ key ] ;
220
+ action_name_spaces = add_command_shortcuts [ key ] [ 'help' ] ;
221
+ action_name = action_name_spaces . replace ( / / g, "-" ) . toLowerCase ( ) ;
222
+ action_full_name = Jupyter . keyboard_manager . actions . register ( action , action_name , prefix ) ;
223
+ Jupyter . keyboard_manager . command_shortcuts . add_shortcut (
224
+ key , action_full_name ) ;
225
+ }
226
+ } ;
227
+ if ( params . toggle_enable_esc_shortcut ) {
228
+ Jupyter . keyboard_manager . command_shortcuts . add_shortcut (
229
+ 'Esc' , 'jupyter-notebook:enter-edit-mode' ) ;
200
230
}
201
231
} ;
202
- for ( var key in add_edit_shortcuts ) {
203
- // check if the property/key is defined in the object itself, not in parent
204
- if ( add_edit_shortcuts . hasOwnProperty ( key ) ) {
205
- action = add_edit_shortcuts [ key ] ;
206
- action_name_spaces = add_edit_shortcuts [ key ] [ 'help' ] ;
207
- action_name = action_name_spaces . replace ( / / g, "-" ) . toLowerCase ( ) ;
208
- action_full_name = Jupyter . keyboard_manager . actions . register ( action , action_name , prefix ) ;
209
- Jupyter . keyboard_manager . edit_shortcuts . add_shortcut ( key , action_full_name ) ;
210
- }
232
+
233
+ if ( params . toggle_enable_edit_shortcuts ) {
234
+ for ( var key in add_edit_shortcuts ) {
235
+ // check if the property/key is defined in the object itself, not in parent
236
+ if ( add_edit_shortcuts . hasOwnProperty ( key ) ) {
237
+ action = add_edit_shortcuts [ key ] ;
238
+ action_name_spaces = add_edit_shortcuts [ key ] [ 'help' ] ;
239
+ action_name = action_name_spaces . replace ( / / g, "-" ) . toLowerCase ( ) ;
240
+ action_full_name = Jupyter . keyboard_manager . actions . register ( action , action_name , prefix ) ;
241
+ Jupyter . keyboard_manager . edit_shortcuts . add_shortcut ( key , action_full_name ) ;
242
+ }
243
+ } ;
244
+ if ( params . toggle_enable_enter_shortcuts ) {
245
+ for ( var key in add_edit_enter_shortcuts ) {
246
+ // check if the property/key is defined in the object itself, not in parent
247
+ if ( add_edit_enter_shortcuts . hasOwnProperty ( key ) ) {
248
+ action = add_edit_enter_shortcuts [ key ] ;
249
+ action_name_spaces = add_edit_enter_shortcuts [ key ] [ 'help' ] ;
250
+ action_name = action_name_spaces . replace ( / / g, "-" ) . toLowerCase ( ) ;
251
+ action_full_name = Jupyter . keyboard_manager . actions . register ( action , action_name , prefix ) ;
252
+ Jupyter . keyboard_manager . edit_shortcuts . add_shortcut (
253
+ key , action_full_name ) ;
254
+ }
255
+ } ;
256
+ } ;
257
+ Jupyter . keyboard_manager . edit_shortcuts . add_shortcut (
258
+ 'alt-add' , 'jupyter-notebook:split-cell-at-cursor' ) ;
211
259
} ;
212
260
213
261
} ;
214
262
263
+ var load_ipython_extension = function ( ) {
264
+ return Jupyter . notebook . config . loaded . then ( initialize ) ;
265
+ } ;
215
266
216
267
var extension = {
217
268
load_ipython_extension : load_ipython_extension
0 commit comments