3
3
define ( [
4
4
'base/js/namespace' ,
5
5
'jquery'
6
- ] , function ( IPython , $ ) {
6
+ ] , function ( Jupyter , $ ) {
7
7
"use strict" ;
8
8
9
9
var add_command_shortcuts = {
10
10
'esc' : {
11
- help : 'edit mode' ,
11
+ help : 'Enter edit mode' ,
12
12
help_index : 'aa' ,
13
13
handler : function ( ) {
14
- IPython . notebook . edit_mode ( ) ;
14
+ Jupyter . notebook . edit_mode ( ) ;
15
15
return false ;
16
16
}
17
17
} ,
18
18
19
19
'home' : {
20
- help : 'go to top' ,
20
+ help : 'Go to top' ,
21
21
help_index : 'ga' ,
22
22
handler : function ( ) {
23
- IPython . notebook . select ( 0 ) ;
24
- IPython . notebook . scroll_to_top ( ) ;
23
+ Jupyter . notebook . select ( 0 ) ;
24
+ Jupyter . notebook . scroll_to_top ( ) ;
25
25
return false ;
26
26
}
27
27
} ,
28
28
29
29
'end' : {
30
- help : 'go to bottom' ,
30
+ help : 'Go to bottom' ,
31
31
help_index : 'ga' ,
32
32
handler : function ( ) {
33
- var ncells = IPython . notebook . ncells ( ) ;
34
- IPython . notebook . select ( ncells - 1 ) ;
35
- IPython . notebook . scroll_to_bottom ( ) ;
33
+ var ncells = Jupyter . notebook . ncells ( ) ;
34
+ Jupyter . notebook . select ( ncells - 1 ) ;
35
+ Jupyter . notebook . scroll_to_bottom ( ) ;
36
36
return false ;
37
37
}
38
38
} ,
39
39
40
40
'pageup' : {
41
- help : 'page up' ,
41
+ help : 'Move page up' ,
42
42
help_index : 'aa' ,
43
43
handler : function ( ) {
44
44
var wh = 0.6 * $ ( window ) . height ( ) ;
45
- var cell = IPython . notebook . get_selected_cell ( ) ;
45
+ var cell = Jupyter . notebook . get_selected_cell ( ) ;
46
46
var h = 0 ;
47
47
/* loop until we have enough cells to span the size of the notebook window (= one page) */
48
48
do {
49
49
h += cell . element . height ( ) ;
50
- IPython . notebook . select_prev ( ) ;
51
- cell = IPython . notebook . get_selected_cell ( ) ;
50
+ Jupyter . notebook . select_prev ( ) ;
51
+ cell = Jupyter . notebook . get_selected_cell ( ) ;
52
52
} while ( h < wh ) ;
53
53
var cp = cell . element . position ( ) ;
54
54
var sp = $ ( 'body' ) . scrollTop ( ) ;
55
55
if ( cp . top < sp ) {
56
- IPython . notebook . scroll_to_cell ( IPython . notebook . get_selected_index ( ) , 0 ) ;
56
+ Jupyter . notebook . scroll_to_cell ( Jupyter . notebook . get_selected_index ( ) , 0 ) ;
57
57
}
58
58
cell . focus_cell ( ) ;
59
59
return false ;
60
60
}
61
61
} ,
62
62
63
63
'pagedown' : {
64
- help : 'page down' ,
64
+ help : 'Move page down' ,
65
65
help_index : 'aa' ,
66
66
handler : function ( ) {
67
67
68
68
/* jump to bottom if we are already in the last cell */
69
- var ncells = IPython . notebook . ncells ( ) ;
70
- if ( IPython . notebook . get_selected_index ( ) + 1 == ncells ) {
71
- IPython . notebook . scroll_to_bottom ( ) ;
69
+ var ncells = Jupyter . notebook . ncells ( ) ;
70
+ if ( Jupyter . notebook . get_selected_index ( ) + 1 == ncells ) {
71
+ Jupyter . notebook . scroll_to_bottom ( ) ;
72
72
return false ;
73
73
}
74
74
75
75
var wh = 0.6 * $ ( window ) . height ( ) ;
76
- var cell = IPython . notebook . get_selected_cell ( ) ;
76
+ var cell = Jupyter . notebook . get_selected_cell ( ) ;
77
77
var h = 0 ;
78
78
79
79
/* loop until we have enough cells to span the size of the notebook window (= one page) */
80
80
do {
81
81
h += cell . element . height ( ) ;
82
- IPython . notebook . select_next ( ) ;
83
- cell = IPython . notebook . get_selected_cell ( ) ;
82
+ Jupyter . notebook . select_next ( ) ;
83
+ cell = Jupyter . notebook . get_selected_cell ( ) ;
84
84
} while ( h < wh ) ;
85
85
cell . focus_cell ( ) ;
86
86
return false ;
@@ -90,119 +90,148 @@ define([
90
90
} ;
91
91
92
92
var add_edit_shortcuts = {
93
- 'alt-add ' : {
94
- help : 'split cell' ,
93
+ 'alt-minus ' : {
94
+ help : 'Split cell at cursor ' ,
95
95
help_index : 'eb' ,
96
96
handler : function ( ) {
97
- IPython . notebook . split_cell ( ) ;
98
- IPython . notebook . edit_mode ( ) ;
97
+ Jupyter . notebook . edit_mode ( ) ;
98
+ Jupyter . notebook . split_cell ( ) ;
99
+ Jupyter . notebook . edit_mode ( ) ;
99
100
return false ;
100
101
}
101
102
} ,
102
- 'alt-subtract ' : {
103
- help : 'merge cell' ,
103
+ 'alt-= ' : {
104
+ help : 'Merge cell with previous cell' ,
104
105
help_index : 'eb' ,
105
106
handler : function ( ) {
106
- var i = IPython . notebook . get_selected_index ( ) ;
107
+ var i = Jupyter . notebook . get_selected_index ( ) ;
107
108
if ( i > 0 ) {
108
- var l = IPython . notebook . get_cell ( i - 1 ) . code_mirror . lineCount ( ) ;
109
- IPython . notebook . merge_cell_above ( ) ;
110
- IPython . notebook . get_selected_cell ( ) . code_mirror . setCursor ( l , 0 ) ;
109
+ var l = Jupyter . notebook . get_cell ( i - 1 ) . code_mirror . lineCount ( ) ;
110
+ Jupyter . notebook . merge_cell_above ( ) ;
111
+ Jupyter . notebook . get_selected_cell ( ) . code_mirror . setCursor ( l , 0 ) ;
111
112
}
112
113
}
113
114
} ,
114
115
'shift-enter' : {
115
- help : 'run cell, select next codecell ' ,
116
+ help : 'Run cell and select next in edit mode ' ,
116
117
help_index : 'bb' ,
117
118
handler : function ( ) {
118
- IPython . notebook . execute_cell_and_select_below ( ) ;
119
- var rendered = IPython . notebook . get_selected_cell ( ) . rendered ;
120
- var ccell = IPython . notebook . get_selected_cell ( ) . cell_type ;
121
- if ( rendered === false || ccell === 'code' ) IPython . notebook . edit_mode ( ) ;
119
+ Jupyter . notebook . execute_cell_and_select_below ( ) ;
120
+ var rendered = Jupyter . notebook . get_selected_cell ( ) . rendered ;
121
+ var ccell = Jupyter . notebook . get_selected_cell ( ) . cell_type ;
122
+ if ( rendered === false || ccell === 'code' ) Jupyter . notebook . edit_mode ( ) ;
122
123
return false ;
123
124
}
124
125
} ,
125
126
'ctrl-enter' : {
126
- help : 'run cell' ,
127
+ help : 'Run selected cell stay in edit mode ' ,
127
128
help_index : 'bb' ,
128
129
handler : function ( ) {
129
- var cell = IPython . notebook . get_selected_cell ( ) ;
130
+ var cell = Jupyter . notebook . get_selected_cell ( ) ;
130
131
var mode = cell . mode ;
131
132
cell . execute ( ) ;
132
- if ( mode === "edit" ) IPython . notebook . edit_mode ( ) ;
133
+ if ( mode === "edit" ) Jupyter . notebook . edit_mode ( ) ;
133
134
return false ;
134
135
}
135
136
} ,
136
137
'alt-n' : {
137
- help : 'toggle line numbers' ,
138
+ help : 'Toggle line numbers' ,
138
139
help_index : 'xy' ,
139
140
handler : function ( ) {
140
- var cell = IPython . notebook . get_selected_cell ( ) ;
141
+ var cell = Jupyter . notebook . get_selected_cell ( ) ;
141
142
cell . toggle_line_numbers ( ) ;
142
143
return false ;
143
144
}
144
145
} ,
145
146
'pagedown' : {
146
- help : 'page down' ,
147
+ help : 'Page down' ,
147
148
help_index : 'xy' ,
148
149
handler : function ( ) {
149
150
150
- var ic = IPython . notebook . get_selected_index ( ) ;
151
- var cells = IPython . notebook . get_cells ( ) ;
151
+ var ic = Jupyter . notebook . get_selected_index ( ) ;
152
+ var cells = Jupyter . notebook . get_cells ( ) ;
152
153
var i , h = 0 ;
153
154
for ( i = 0 ; i < ic ; i ++ ) {
154
155
h += cells [ i ] . element . height ( ) ;
155
156
}
156
157
var cur = cells [ ic ] . code_mirror . getCursor ( ) ;
157
158
h += cells [ ic ] . code_mirror . defaultTextHeight ( ) * cur . line ;
158
- IPython . notebook . element . animate ( { scrollTop :h } , 0 ) ;
159
+ Jupyter . notebook . element . animate ( { scrollTop :h } , 0 ) ;
159
160
return false ;
160
161
}
161
162
} ,
162
163
'pageup' : {
163
- help : 'page down ' ,
164
+ help : 'Page up ' ,
164
165
help_index : 'xy' ,
165
166
handler : function ( ) {
166
167
167
- var ic = IPython . notebook . get_selected_index ( ) ;
168
- var cells = IPython . notebook . get_cells ( ) ;
168
+ var ic = Jupyter . notebook . get_selected_index ( ) ;
169
+ var cells = Jupyter . notebook . get_cells ( ) ;
169
170
var i , h = 0 ;
170
171
for ( i = 0 ; i < ic ; i ++ ) {
171
172
h += cells [ i ] . element . height ( ) ;
172
173
}
173
174
var cur = cells [ ic ] . code_mirror . getCursor ( ) ;
174
175
h += cells [ ic ] . code_mirror . defaultTextHeight ( ) * cur . line ;
175
- IPython . notebook . element . animate ( { scrollTop :h } , 0 ) ;
176
+ Jupyter . notebook . element . animate ( { scrollTop :h } , 0 ) ;
176
177
return false ;
177
178
}
178
179
} ,
179
180
'ctrl-y' : {
180
- help : 'toggle markdown/code' ,
181
+ help : 'Toggle markdown/code' ,
181
182
handler : function ( ) {
182
- var cell = IPython . notebook . get_selected_cell ( ) ;
183
+ var cell = Jupyter . notebook . get_selected_cell ( ) ;
183
184
var cur = cell . code_mirror . getCursor ( ) ;
184
185
if ( cell . cell_type == 'code' ) {
185
- IPython . notebook . command_mode ( ) ;
186
- IPython . notebook . to_markdown ( ) ;
187
- IPython . notebook . edit_mode ( ) ;
188
- cell = IPython . notebook . get_selected_cell ( ) ;
186
+ Jupyter . notebook . command_mode ( ) ;
187
+ Jupyter . notebook . to_markdown ( ) ;
188
+ Jupyter . notebook . edit_mode ( ) ;
189
+ cell = Jupyter . notebook . get_selected_cell ( ) ;
189
190
cell . code_mirror . setCursor ( cur ) ;
190
191
} else if ( cell . cell_type == 'markdown' ) {
191
- IPython . notebook . command_mode ( ) ;
192
- IPython . notebook . to_code ( ) ;
193
- IPython . notebook . edit_mode ( ) ;
194
- cell = IPython . notebook . get_selected_cell ( ) ;
192
+ Jupyter . notebook . command_mode ( ) ;
193
+ Jupyter . notebook . to_code ( ) ;
194
+ Jupyter . notebook . edit_mode ( ) ;
195
+ cell = Jupyter . notebook . get_selected_cell ( ) ;
195
196
cell . code_mirror . setCursor ( cur ) ;
196
197
}
197
198
return false ;
198
199
}
199
200
}
200
201
} ;
201
202
203
+
202
204
var load_ipython_extension = function ( ) {
203
- IPython . keyboard_manager . edit_shortcuts . add_shortcuts ( add_edit_shortcuts ) ;
204
- IPython . keyboard_manager . command_shortcuts . add_shortcuts ( add_command_shortcuts ) ;
205
+ var action ;
206
+ var prefix = 'navigation_hotkeys' ;
207
+ var action_name ;
208
+ var action_name_spaces ;
209
+ var action_full_name ;
210
+
211
+ for ( var key in add_command_shortcuts ) {
212
+ // check if the property/key is defined in the object itself, not in parent
213
+ if ( add_command_shortcuts . hasOwnProperty ( key ) ) {
214
+ action = add_command_shortcuts [ key ] ;
215
+ action_name_spaces = add_command_shortcuts [ key ] [ 'help' ] ;
216
+ action_name = action_name_spaces . replace ( / / g, "-" ) . toLowerCase ( ) ;
217
+ action_full_name = Jupyter . keyboard_manager . actions . register ( action , action_name , prefix ) ;
218
+ Jupyter . keyboard_manager . command_shortcuts . add_shortcut ( key , action_full_name ) ;
219
+ }
220
+ } ;
221
+ for ( var key in add_edit_shortcuts ) {
222
+ // check if the property/key is defined in the object itself, not in parent
223
+ if ( add_edit_shortcuts . hasOwnProperty ( key ) ) {
224
+ action = add_edit_shortcuts [ key ] ;
225
+ action_name_spaces = add_edit_shortcuts [ key ] [ 'help' ] ;
226
+ action_name = action_name_spaces . replace ( / / g, "-" ) . toLowerCase ( ) ;
227
+ action_full_name = Jupyter . keyboard_manager . actions . register ( action , action_name , prefix ) ;
228
+ Jupyter . keyboard_manager . edit_shortcuts . add_shortcut ( key , action_full_name ) ;
229
+ }
230
+ } ;
231
+
205
232
} ;
233
+
234
+
206
235
var extension = {
207
236
load_ipython_extension : load_ipython_extension
208
237
} ;
0 commit comments