Show More
This diff has been collapsed as it changes many lines, (723 lines changed) Show them Hide them | |||||
@@ -1,7 +1,12 | |||||
1 | // Copyright (c) IPython Development Team. |
|
1 | // Copyright (c) IPython Development Team. | |
2 | // Distributed under the terms of the Modified BSD License. |
|
2 | // Distributed under the terms of the Modified BSD License. | |
3 |
|
3 | |||
4 | var IPython = (function (IPython) { |
|
4 | define([ | |
|
5 | 'base/js/namespace', | |||
|
6 | 'jquery', | |||
|
7 | 'base/js/utils', | |||
|
8 | 'base/js/keyboard', | |||
|
9 | ], function(IPython, $, utils, keyboard) { | |||
5 | "use strict"; |
|
10 | "use strict"; | |
6 |
|
11 | |||
7 | var browser = utils.browser[0]; |
|
12 | var browser = utils.browser[0]; | |
@@ -98,386 +103,386 var IPython = (function (IPython) { | |||||
98 | KeyboardManager.prototype.get_default_edit_shortcuts = function() { |
|
103 | KeyboardManager.prototype.get_default_edit_shortcuts = function() { | |
99 | var that = this; |
|
104 | var that = this; | |
100 | return { |
|
105 | return { | |
101 | 'esc' : { |
|
106 | 'esc' : { | |
102 | help : 'command mode', |
|
107 | help : 'command mode', | |
103 | help_index : 'aa', |
|
108 | help_index : 'aa', | |
104 | handler : function (event) { |
|
109 | handler : function (event) { | |
105 | that.notebook.command_mode(); |
|
|||
106 | return false; |
|
|||
107 | } |
|
|||
108 | }, |
|
|||
109 | 'ctrl-m' : { |
|
|||
110 | help : 'command mode', |
|
|||
111 | help_index : 'ab', |
|
|||
112 | handler : function (event) { |
|
|||
113 | that.notebook.command_mode(); |
|
|||
114 | return false; |
|
|||
115 | } |
|
|||
116 | }, |
|
|||
117 | 'up' : { |
|
|||
118 | help : '', |
|
|||
119 | help_index : '', |
|
|||
120 | handler : function (event) { |
|
|||
121 | var index = that.notebook.get_selected_index(); |
|
|||
122 | var cell = that.notebook.get_cell(index); |
|
|||
123 | if (cell && cell.at_top() && index !== 0) { |
|
|||
124 | event.preventDefault(); |
|
|||
125 | that.notebook.command_mode(); |
|
110 | that.notebook.command_mode(); | |
126 | that.notebook.select_prev(); |
|
|||
127 | that.notebook.edit_mode(); |
|
|||
128 | var cm = that.notebook.get_selected_cell().code_mirror; |
|
|||
129 | cm.setCursor(cm.lastLine(), 0); |
|
|||
130 | return false; |
|
|||
131 | } else if (cell) { |
|
|||
132 | var cm = cell.code_mirror; |
|
|||
133 | cm.execCommand('goLineUp'); |
|
|||
134 | return false; |
|
111 | return false; | |
135 | } |
|
112 | } | |
136 | } |
|
113 | }, | |
137 | }, |
|
114 | 'ctrl-m' : { | |
138 | 'down' : { |
|
115 | help : 'command mode', | |
139 |
|
|
116 | help_index : 'ab', | |
140 | help_index : '', |
|
117 | handler : function (event) { | |
141 | handler : function (event) { |
|
|||
142 | var index = that.notebook.get_selected_index(); |
|
|||
143 | var cell = that.notebook.get_cell(index); |
|
|||
144 | if (cell.at_bottom() && index !== (that.notebook.ncells()-1)) { |
|
|||
145 | event.preventDefault(); |
|
|||
146 | that.notebook.command_mode(); |
|
118 | that.notebook.command_mode(); | |
147 | that.notebook.select_next(); |
|
|||
148 | that.notebook.edit_mode(); |
|
|||
149 | var cm = that.notebook.get_selected_cell().code_mirror; |
|
|||
150 | cm.setCursor(0, 0); |
|
|||
151 | return false; |
|
119 | return false; | |
152 |
} |
|
120 | } | |
153 | var cm = cell.code_mirror; |
|
121 | }, | |
154 | cm.execCommand('goLineDown'); |
|
122 | 'up' : { | |
|
123 | help : '', | |||
|
124 | help_index : '', | |||
|
125 | handler : function (event) { | |||
|
126 | var index = that.notebook.get_selected_index(); | |||
|
127 | var cell = that.notebook.get_cell(index); | |||
|
128 | if (cell && cell.at_top() && index !== 0) { | |||
|
129 | event.preventDefault(); | |||
|
130 | that.notebook.command_mode(); | |||
|
131 | that.notebook.select_prev(); | |||
|
132 | that.notebook.edit_mode(); | |||
|
133 | var cm = that.notebook.get_selected_cell().code_mirror; | |||
|
134 | cm.setCursor(cm.lastLine(), 0); | |||
|
135 | return false; | |||
|
136 | } else if (cell) { | |||
|
137 | var cm = cell.code_mirror; | |||
|
138 | cm.execCommand('goLineUp'); | |||
|
139 | return false; | |||
|
140 | } | |||
|
141 | } | |||
|
142 | }, | |||
|
143 | 'down' : { | |||
|
144 | help : '', | |||
|
145 | help_index : '', | |||
|
146 | handler : function (event) { | |||
|
147 | var index = that.notebook.get_selected_index(); | |||
|
148 | var cell = that.notebook.get_cell(index); | |||
|
149 | if (cell.at_bottom() && index !== (that.notebook.ncells()-1)) { | |||
|
150 | event.preventDefault(); | |||
|
151 | that.notebook.command_mode(); | |||
|
152 | that.notebook.select_next(); | |||
|
153 | that.notebook.edit_mode(); | |||
|
154 | var cm = that.notebook.get_selected_cell().code_mirror; | |||
|
155 | cm.setCursor(0, 0); | |||
|
156 | return false; | |||
|
157 | } else { | |||
|
158 | var cm = cell.code_mirror; | |||
|
159 | cm.execCommand('goLineDown'); | |||
|
160 | return false; | |||
|
161 | } | |||
|
162 | } | |||
|
163 | }, | |||
|
164 | 'ctrl-shift--' : { | |||
|
165 | help : 'split cell', | |||
|
166 | help_index : 'ea', | |||
|
167 | handler : function (event) { | |||
|
168 | that.notebook.split_cell(); | |||
155 | return false; |
|
169 | return false; | |
156 | } |
|
170 | } | |
157 | } |
|
171 | }, | |
158 | }, |
|
172 | 'ctrl-shift-subtract' : { | |
159 | 'ctrl-shift--' : { |
|
173 | help : '', | |
160 |
|
|
174 | help_index : 'eb', | |
161 | help_index : 'ea', |
|
175 | handler : function (event) { | |
162 | handler : function (event) { |
|
176 | that.notebook.split_cell(); | |
163 |
|
|
177 | return false; | |
164 |
|
|
178 | } | |
165 | } |
|
179 | }, | |
166 |
} |
|
180 | }; | |
167 | 'ctrl-shift-subtract' : { |
|
|||
168 | help : '', |
|
|||
169 | help_index : 'eb', |
|
|||
170 | handler : function (event) { |
|
|||
171 | that.notebook.split_cell(); |
|
|||
172 | return false; |
|
|||
173 | } |
|
|||
174 | }, |
|
|||
175 | }; |
|
|||
176 | }; |
|
181 | }; | |
177 |
|
182 | |||
178 | KeyboardManager.prototype.get_default_command_shortcuts = function() { |
|
183 | KeyboardManager.prototype.get_default_command_shortcuts = function() { | |
179 | var that = this; |
|
184 | var that = this; | |
180 | return { |
|
185 | return { | |
181 | 'space': { |
|
186 | 'space': { | |
182 | help: "Scroll down to next H1 cell", |
|
187 | help: "Scroll down to next H1 cell", | |
183 | handler: function(event) { |
|
188 | handler: function(event) { | |
184 | return that.notebook.scrollmanager.scroll(1); |
|
189 | return that.notebook.scrollmanager.scroll(1); | |
|
190 | }, | |||
185 | }, |
|
191 | }, | |
186 | }, |
|
192 | 'shift-space': { | |
187 | 'shift-space': { |
|
193 | help: "Scroll up to previous H1 cell", | |
188 | help: "Scroll up to previous H1 cell", |
|
194 | handler: function(event) { | |
189 | handler: function(event) { |
|
195 | return that.notebook.scrollmanager.scroll(-1); | |
190 | return that.notebook.scrollmanager.scroll(-1); |
|
196 | }, | |
191 | }, |
|
197 | }, | |
192 | }, |
|
198 | 'enter' : { | |
193 | 'enter' : { |
|
199 | help : 'edit mode', | |
194 |
|
|
200 | help_index : 'aa', | |
195 | help_index : 'aa', |
|
201 | handler : function (event) { | |
196 | handler : function (event) { |
|
202 | that.notebook.edit_mode(); | |
197 |
|
|
203 | return false; | |
198 | return false; |
|
|||
199 | } |
|
|||
200 | }, |
|
|||
201 | 'up' : { |
|
|||
202 | help : 'select previous cell', |
|
|||
203 | help_index : 'da', |
|
|||
204 | handler : function (event) { |
|
|||
205 | var index = that.notebook.get_selected_index(); |
|
|||
206 | if (index !== 0 && index !== null) { |
|
|||
207 | that.notebook.select_prev(); |
|
|||
208 | that.notebook.focus_cell(); |
|
|||
209 | } |
|
204 | } | |
210 | return false; |
|
205 | }, | |
211 |
|
|
206 | 'up' : { | |
212 | }, |
|
207 | help : 'select previous cell', | |
213 | 'down' : { |
|
208 | help_index : 'da', | |
214 | help : 'select next cell', |
|
209 | handler : function (event) { | |
215 | help_index : 'db', |
|
210 | var index = that.notebook.get_selected_index(); | |
216 | handler : function (event) { |
|
211 | if (index !== 0 && index !== null) { | |
217 |
|
|
212 | that.notebook.select_prev(); | |
218 |
|
|
213 | that.notebook.focus_cell(); | |
219 | that.notebook.select_next(); |
|
214 | } | |
220 | that.notebook.focus_cell(); |
|
215 | return false; | |
221 | } |
|
216 | } | |
222 | return false; |
|
217 | }, | |
223 |
|
|
218 | 'down' : { | |
224 | }, |
|
219 | help : 'select next cell', | |
225 | 'k' : { |
|
220 | help_index : 'db', | |
226 | help : 'select previous cell', |
|
221 | handler : function (event) { | |
227 | help_index : 'dc', |
|
222 | var index = that.notebook.get_selected_index(); | |
228 | handler : function (event) { |
|
223 | if (index !== (that.notebook.ncells()-1) && index !== null) { | |
229 |
|
|
224 | that.notebook.select_next(); | |
230 | if (index !== 0 && index !== null) { |
|
225 | that.notebook.focus_cell(); | |
|
226 | } | |||
|
227 | return false; | |||
|
228 | } | |||
|
229 | }, | |||
|
230 | 'k' : { | |||
|
231 | help : 'select previous cell', | |||
|
232 | help_index : 'dc', | |||
|
233 | handler : function (event) { | |||
|
234 | var index = that.notebook.get_selected_index(); | |||
|
235 | if (index !== 0 && index !== null) { | |||
|
236 | that.notebook.select_prev(); | |||
|
237 | that.notebook.focus_cell(); | |||
|
238 | } | |||
|
239 | return false; | |||
|
240 | } | |||
|
241 | }, | |||
|
242 | 'j' : { | |||
|
243 | help : 'select next cell', | |||
|
244 | help_index : 'dd', | |||
|
245 | handler : function (event) { | |||
|
246 | var index = that.notebook.get_selected_index(); | |||
|
247 | if (index !== (that.notebook.ncells()-1) && index !== null) { | |||
|
248 | that.notebook.select_next(); | |||
|
249 | that.notebook.focus_cell(); | |||
|
250 | } | |||
|
251 | return false; | |||
|
252 | } | |||
|
253 | }, | |||
|
254 | 'x' : { | |||
|
255 | help : 'cut cell', | |||
|
256 | help_index : 'ee', | |||
|
257 | handler : function (event) { | |||
|
258 | that.notebook.cut_cell(); | |||
|
259 | return false; | |||
|
260 | } | |||
|
261 | }, | |||
|
262 | 'c' : { | |||
|
263 | help : 'copy cell', | |||
|
264 | help_index : 'ef', | |||
|
265 | handler : function (event) { | |||
|
266 | that.notebook.copy_cell(); | |||
|
267 | return false; | |||
|
268 | } | |||
|
269 | }, | |||
|
270 | 'shift-v' : { | |||
|
271 | help : 'paste cell above', | |||
|
272 | help_index : 'eg', | |||
|
273 | handler : function (event) { | |||
|
274 | that.notebook.paste_cell_above(); | |||
|
275 | return false; | |||
|
276 | } | |||
|
277 | }, | |||
|
278 | 'v' : { | |||
|
279 | help : 'paste cell below', | |||
|
280 | help_index : 'eh', | |||
|
281 | handler : function (event) { | |||
|
282 | that.notebook.paste_cell_below(); | |||
|
283 | return false; | |||
|
284 | } | |||
|
285 | }, | |||
|
286 | 'd' : { | |||
|
287 | help : 'delete cell (press twice)', | |||
|
288 | help_index : 'ej', | |||
|
289 | count: 2, | |||
|
290 | handler : function (event) { | |||
|
291 | that.notebook.delete_cell(); | |||
|
292 | return false; | |||
|
293 | } | |||
|
294 | }, | |||
|
295 | 'a' : { | |||
|
296 | help : 'insert cell above', | |||
|
297 | help_index : 'ec', | |||
|
298 | handler : function (event) { | |||
|
299 | that.notebook.insert_cell_above(); | |||
231 | that.notebook.select_prev(); |
|
300 | that.notebook.select_prev(); | |
232 | that.notebook.focus_cell(); |
|
301 | that.notebook.focus_cell(); | |
|
302 | return false; | |||
233 | } |
|
303 | } | |
234 | return false; |
|
304 | }, | |
235 |
|
|
305 | 'b' : { | |
236 | }, |
|
306 | help : 'insert cell below', | |
237 | 'j' : { |
|
307 | help_index : 'ed', | |
238 | help : 'select next cell', |
|
308 | handler : function (event) { | |
239 | help_index : 'dd', |
|
309 | that.notebook.insert_cell_below(); | |
240 | handler : function (event) { |
|
|||
241 | var index = that.notebook.get_selected_index(); |
|
|||
242 | if (index !== (that.notebook.ncells()-1) && index !== null) { |
|
|||
243 | that.notebook.select_next(); |
|
310 | that.notebook.select_next(); | |
244 | that.notebook.focus_cell(); |
|
311 | that.notebook.focus_cell(); | |
|
312 | return false; | |||
245 | } |
|
313 | } | |
246 | return false; |
|
314 | }, | |
247 |
|
|
315 | 'y' : { | |
248 | }, |
|
316 | help : 'to code', | |
249 | 'x' : { |
|
317 | help_index : 'ca', | |
250 | help : 'cut cell', |
|
318 | handler : function (event) { | |
251 | help_index : 'ee', |
|
319 | that.notebook.to_code(); | |
252 | handler : function (event) { |
|
320 | return false; | |
253 | that.notebook.cut_cell(); |
|
321 | } | |
254 | return false; |
|
322 | }, | |
255 |
|
|
323 | 'm' : { | |
256 | }, |
|
324 | help : 'to markdown', | |
257 | 'c' : { |
|
325 | help_index : 'cb', | |
258 | help : 'copy cell', |
|
326 | handler : function (event) { | |
259 | help_index : 'ef', |
|
327 | that.notebook.to_markdown(); | |
260 | handler : function (event) { |
|
328 | return false; | |
261 | that.notebook.copy_cell(); |
|
329 | } | |
262 | return false; |
|
330 | }, | |
263 |
|
|
331 | 'r' : { | |
264 | }, |
|
332 | help : 'to raw', | |
265 | 'shift-v' : { |
|
333 | help_index : 'cc', | |
266 | help : 'paste cell above', |
|
334 | handler : function (event) { | |
267 | help_index : 'eg', |
|
335 | that.notebook.to_raw(); | |
268 | handler : function (event) { |
|
336 | return false; | |
269 | that.notebook.paste_cell_above(); |
|
337 | } | |
270 | return false; |
|
338 | }, | |
271 |
|
|
339 | '1' : { | |
272 | }, |
|
340 | help : 'to heading 1', | |
273 | 'v' : { |
|
341 | help_index : 'cd', | |
274 | help : 'paste cell below', |
|
342 | handler : function (event) { | |
275 | help_index : 'eh', |
|
343 | that.notebook.to_heading(undefined, 1); | |
276 | handler : function (event) { |
|
344 | return false; | |
277 | that.notebook.paste_cell_below(); |
|
345 | } | |
278 | return false; |
|
346 | }, | |
279 |
|
|
347 | '2' : { | |
280 | }, |
|
348 | help : 'to heading 2', | |
281 | 'd' : { |
|
349 | help_index : 'ce', | |
282 | help : 'delete cell (press twice)', |
|
350 | handler : function (event) { | |
283 | help_index : 'ej', |
|
351 | that.notebook.to_heading(undefined, 2); | |
284 | count: 2, |
|
352 | return false; | |
285 | handler : function (event) { |
|
353 | } | |
286 | that.notebook.delete_cell(); |
|
354 | }, | |
287 | return false; |
|
355 | '3' : { | |
288 | } |
|
356 | help : 'to heading 3', | |
289 | }, |
|
357 | help_index : 'cf', | |
290 | 'a' : { |
|
358 | handler : function (event) { | |
291 | help : 'insert cell above', |
|
359 | that.notebook.to_heading(undefined, 3); | |
292 | help_index : 'ec', |
|
360 | return false; | |
293 | handler : function (event) { |
|
361 | } | |
294 | that.notebook.insert_cell_above(); |
|
362 | }, | |
295 | that.notebook.select_prev(); |
|
363 | '4' : { | |
296 | that.notebook.focus_cell(); |
|
364 | help : 'to heading 4', | |
297 |
|
|
365 | help_index : 'cg', | |
298 | } |
|
366 | handler : function (event) { | |
299 | }, |
|
367 | that.notebook.to_heading(undefined, 4); | |
300 | 'b' : { |
|
368 | return false; | |
301 | help : 'insert cell below', |
|
369 | } | |
302 | help_index : 'ed', |
|
370 | }, | |
303 | handler : function (event) { |
|
371 | '5' : { | |
304 | that.notebook.insert_cell_below(); |
|
372 | help : 'to heading 5', | |
305 | that.notebook.select_next(); |
|
373 | help_index : 'ch', | |
306 | that.notebook.focus_cell(); |
|
374 | handler : function (event) { | |
307 | return false; |
|
375 | that.notebook.to_heading(undefined, 5); | |
308 | } |
|
376 | return false; | |
309 |
} |
|
377 | } | |
310 |
|
|
378 | }, | |
311 | help : 'to code', |
|
379 | '6' : { | |
312 |
|
|
380 | help : 'to heading 6', | |
313 | handler : function (event) { |
|
381 | help_index : 'ci', | |
314 | that.notebook.to_code(); |
|
382 | handler : function (event) { | |
315 | return false; |
|
383 | that.notebook.to_heading(undefined, 6); | |
316 | } |
|
384 | return false; | |
317 |
} |
|
385 | } | |
318 |
|
|
386 | }, | |
319 | help : 'to markdown', |
|
387 | 'o' : { | |
320 |
|
|
388 | help : 'toggle output', | |
321 | handler : function (event) { |
|
389 | help_index : 'gb', | |
322 | that.notebook.to_markdown(); |
|
390 | handler : function (event) { | |
323 | return false; |
|
391 | that.notebook.toggle_output(); | |
324 | } |
|
392 | return false; | |
325 |
} |
|
393 | } | |
326 |
|
|
394 | }, | |
327 | help : 'to raw', |
|
395 | 'shift-o' : { | |
328 | help_index : 'cc', |
|
396 | help : 'toggle output scrolling', | |
329 | handler : function (event) { |
|
397 | help_index : 'gc', | |
330 | that.notebook.to_raw(); |
|
398 | handler : function (event) { | |
331 | return false; |
|
399 | that.notebook.toggle_output_scroll(); | |
332 | } |
|
400 | return false; | |
333 |
} |
|
401 | } | |
334 |
|
|
402 | }, | |
335 | help : 'to heading 1', |
|
403 | 's' : { | |
336 |
|
|
404 | help : 'save notebook', | |
337 | handler : function (event) { |
|
405 | help_index : 'fa', | |
338 | that.notebook.to_heading(undefined, 1); |
|
406 | handler : function (event) { | |
339 | return false; |
|
407 | that.notebook.save_checkpoint(); | |
340 | } |
|
408 | return false; | |
341 |
} |
|
409 | } | |
342 |
|
|
410 | }, | |
343 | help : 'to heading 2', |
|
411 | 'ctrl-j' : { | |
344 |
|
|
412 | help : 'move cell down', | |
345 | handler : function (event) { |
|
413 | help_index : 'eb', | |
346 | that.notebook.to_heading(undefined, 2); |
|
414 | handler : function (event) { | |
347 | return false; |
|
415 | that.notebook.move_cell_down(); | |
348 | } |
|
416 | return false; | |
349 |
} |
|
417 | } | |
350 |
|
|
418 | }, | |
351 | help : 'to heading 3', |
|
419 | 'ctrl-k' : { | |
352 |
|
|
420 | help : 'move cell up', | |
353 | handler : function (event) { |
|
421 | help_index : 'ea', | |
354 | that.notebook.to_heading(undefined, 3); |
|
422 | handler : function (event) { | |
355 | return false; |
|
423 | that.notebook.move_cell_up(); | |
356 | } |
|
424 | return false; | |
357 |
} |
|
425 | } | |
358 |
|
|
426 | }, | |
359 | help : 'to heading 4', |
|
427 | 'l' : { | |
360 | help_index : 'cg', |
|
428 | help : 'toggle line numbers', | |
361 | handler : function (event) { |
|
429 | help_index : 'ga', | |
362 | that.notebook.to_heading(undefined, 4); |
|
430 | handler : function (event) { | |
363 | return false; |
|
431 | that.notebook.cell_toggle_line_numbers(); | |
364 | } |
|
432 | return false; | |
365 |
} |
|
433 | } | |
366 |
|
|
434 | }, | |
367 | help : 'to heading 5', |
|
435 | 'i' : { | |
368 | help_index : 'ch', |
|
436 | help : 'interrupt kernel (press twice)', | |
369 | handler : function (event) { |
|
437 | help_index : 'ha', | |
370 | that.notebook.to_heading(undefined, 5); |
|
438 | count: 2, | |
371 | return false; |
|
439 | handler : function (event) { | |
372 | } |
|
440 | that.notebook.kernel.interrupt(); | |
373 | }, |
|
441 | return false; | |
374 |
|
|
442 | } | |
375 | help : 'to heading 6', |
|
443 | }, | |
376 |
|
|
444 | '0' : { | |
377 | handler : function (event) { |
|
445 | help : 'restart kernel (press twice)', | |
378 | that.notebook.to_heading(undefined, 6); |
|
446 | help_index : 'hb', | |
379 |
|
|
447 | count: 2, | |
380 | } |
|
448 | handler : function (event) { | |
381 | }, |
|
449 | that.notebook.restart_kernel(); | |
382 | 'o' : { |
|
450 | return false; | |
383 | help : 'toggle output', |
|
451 | } | |
384 | help_index : 'gb', |
|
452 | }, | |
385 | handler : function (event) { |
|
453 | 'h' : { | |
386 | that.notebook.toggle_output(); |
|
454 | help : 'keyboard shortcuts', | |
387 |
|
|
455 | help_index : 'ge', | |
388 | } |
|
456 | handler : function (event) { | |
389 | }, |
|
457 | that.quick_help.show_keyboard_shortcuts(); | |
390 | 'shift-o' : { |
|
458 | return false; | |
391 | help : 'toggle output scrolling', |
|
459 | } | |
392 | help_index : 'gc', |
|
460 | }, | |
393 | handler : function (event) { |
|
461 | 'z' : { | |
394 | that.notebook.toggle_output_scroll(); |
|
462 | help : 'undo last delete', | |
395 |
|
|
463 | help_index : 'ei', | |
396 | } |
|
464 | handler : function (event) { | |
397 | }, |
|
465 | that.notebook.undelete_cell(); | |
398 | 's' : { |
|
466 | return false; | |
399 | help : 'save notebook', |
|
467 | } | |
400 | help_index : 'fa', |
|
468 | }, | |
401 | handler : function (event) { |
|
469 | 'shift-m' : { | |
402 | that.notebook.save_checkpoint(); |
|
470 | help : 'merge cell below', | |
403 |
|
|
471 | help_index : 'ek', | |
404 | } |
|
472 | handler : function (event) { | |
405 | }, |
|
473 | that.notebook.merge_cell_below(); | |
406 | 'ctrl-j' : { |
|
474 | return false; | |
407 | help : 'move cell down', |
|
475 | } | |
408 | help_index : 'eb', |
|
476 | }, | |
409 | handler : function (event) { |
|
477 | 'q' : { | |
410 | that.notebook.move_cell_down(); |
|
478 | help : 'close pager', | |
411 |
|
|
479 | help_index : 'gd', | |
412 | } |
|
480 | handler : function (event) { | |
413 | }, |
|
481 | that.pager.collapse(); | |
414 | 'ctrl-k' : { |
|
482 | return false; | |
415 | help : 'move cell up', |
|
483 | } | |
416 | help_index : 'ea', |
|
484 | }, | |
417 | handler : function (event) { |
|
485 | }; | |
418 | that.notebook.move_cell_up(); |
|
|||
419 | return false; |
|
|||
420 | } |
|
|||
421 | }, |
|
|||
422 | 'l' : { |
|
|||
423 | help : 'toggle line numbers', |
|
|||
424 | help_index : 'ga', |
|
|||
425 | handler : function (event) { |
|
|||
426 | that.notebook.cell_toggle_line_numbers(); |
|
|||
427 | return false; |
|
|||
428 | } |
|
|||
429 | }, |
|
|||
430 | 'i' : { |
|
|||
431 | help : 'interrupt kernel (press twice)', |
|
|||
432 | help_index : 'ha', |
|
|||
433 | count: 2, |
|
|||
434 | handler : function (event) { |
|
|||
435 | that.notebook.kernel.interrupt(); |
|
|||
436 | return false; |
|
|||
437 | } |
|
|||
438 | }, |
|
|||
439 | '0' : { |
|
|||
440 | help : 'restart kernel (press twice)', |
|
|||
441 | help_index : 'hb', |
|
|||
442 | count: 2, |
|
|||
443 | handler : function (event) { |
|
|||
444 | that.notebook.restart_kernel(); |
|
|||
445 | return false; |
|
|||
446 | } |
|
|||
447 | }, |
|
|||
448 | 'h' : { |
|
|||
449 | help : 'keyboard shortcuts', |
|
|||
450 | help_index : 'ge', |
|
|||
451 | handler : function (event) { |
|
|||
452 | that.quick_help.show_keyboard_shortcuts(); |
|
|||
453 | return false; |
|
|||
454 | } |
|
|||
455 | }, |
|
|||
456 | 'z' : { |
|
|||
457 | help : 'undo last delete', |
|
|||
458 | help_index : 'ei', |
|
|||
459 | handler : function (event) { |
|
|||
460 | that.notebook.undelete_cell(); |
|
|||
461 | return false; |
|
|||
462 | } |
|
|||
463 | }, |
|
|||
464 | 'shift-m' : { |
|
|||
465 | help : 'merge cell below', |
|
|||
466 | help_index : 'ek', |
|
|||
467 | handler : function (event) { |
|
|||
468 | that.notebook.merge_cell_below(); |
|
|||
469 | return false; |
|
|||
470 | } |
|
|||
471 | }, |
|
|||
472 | 'q' : { |
|
|||
473 | help : 'close pager', |
|
|||
474 | help_index : 'gd', |
|
|||
475 | handler : function (event) { |
|
|||
476 | that.pager.collapse(); |
|
|||
477 | return false; |
|
|||
478 | } |
|
|||
479 | }, |
|
|||
480 | }; |
|
|||
481 | }; |
|
486 | }; | |
482 |
|
487 | |||
483 | KeyboardManager.prototype.bind_events = function () { |
|
488 | KeyboardManager.prototype.bind_events = function () { |
@@ -19,7 +19,6 require([ | |||||
19 | 'notebook/js/keyboardmanager', |
|
19 | 'notebook/js/keyboardmanager', | |
20 | 'notebook/js/config', |
|
20 | 'notebook/js/config', | |
21 | 'notebook/js/kernelselector', |
|
21 | 'notebook/js/kernelselector', | |
22 | 'notebook/js/scrollmanager' |
|
|||
23 | // only loaded, not used: |
|
22 | // only loaded, not used: | |
24 | 'custom/custom', |
|
23 | 'custom/custom', | |
25 | ], function( |
|
24 | ], function( | |
@@ -39,8 +38,7 require([ | |||||
39 | savewidget, |
|
38 | savewidget, | |
40 | keyboardmanager, |
|
39 | keyboardmanager, | |
41 | config, |
|
40 | config, | |
42 |
kernelselector |
|
41 | kernelselector | |
43 | scrollmanager |
|
|||
44 | ) { |
|
42 | ) { | |
45 | "use strict"; |
|
43 | "use strict"; | |
46 |
|
44 | |||
@@ -69,7 +67,6 require([ | |||||
69 | save_widget: save_widget, |
|
67 | save_widget: save_widget, | |
70 | config: user_config}, |
|
68 | config: user_config}, | |
71 | common_options)); |
|
69 | common_options)); | |
72 | var scrollmanager = new scrollmanager.ScrollManager(notebook); |
|
|||
73 | var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options); |
|
70 | var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options); | |
74 | var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', { |
|
71 | var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', { | |
75 | notebook: notebook, |
|
72 | notebook: notebook, | |
@@ -135,7 +132,6 require([ | |||||
135 | IPython.save_widget = save_widget; |
|
132 | IPython.save_widget = save_widget; | |
136 | IPython.config = user_config; |
|
133 | IPython.config = user_config; | |
137 | IPython.tooltip = notebook.tooltip; |
|
134 | IPython.tooltip = notebook.tooltip; | |
138 | IPython.scrollmanager = scrollmanager; |
|
|||
139 |
|
135 | |||
140 | events.trigger('app_initialized.NotebookApp'); |
|
136 | events.trigger('app_initialized.NotebookApp'); | |
141 | notebook.load_notebook(common_options.notebook_name, common_options.notebook_path); |
|
137 | notebook.load_notebook(common_options.notebook_name, common_options.notebook_path); |
@@ -6,7 +6,8 define([ | |||||
6 | 'jquery', |
|
6 | 'jquery', | |
7 | 'notebook/js/toolbar', |
|
7 | 'notebook/js/toolbar', | |
8 | 'notebook/js/celltoolbar', |
|
8 | 'notebook/js/celltoolbar', | |
9 | ], function(IPython, $, toolbar, celltoolbar) { |
|
9 | 'notebook/js/scrollmanager' | |
|
10 | ], function(IPython, $, toolbar, celltoolbar, scrollmanager) { | |||
10 | "use strict"; |
|
11 | "use strict"; | |
11 |
|
12 | |||
12 | var MainToolBar = function (selector, options) { |
|
13 | var MainToolBar = function (selector, options) { | |
@@ -24,6 +25,7 define([ | |||||
24 | this.construct(); |
|
25 | this.construct(); | |
25 | this.add_celltype_list(); |
|
26 | this.add_celltype_list(); | |
26 | this.add_celltoolbar_list(); |
|
27 | this.add_celltoolbar_list(); | |
|
28 | this.add_scrollmanager_list(); | |||
27 | this.bind_events(); |
|
29 | this.bind_events(); | |
28 | }; |
|
30 | }; | |
29 |
|
31 | |||
@@ -187,6 +189,11 define([ | |||||
187 | }; |
|
189 | }; | |
188 |
|
190 | |||
189 |
|
191 | |||
|
192 | MainToolBar.prototype.add_scrollmanager_list = function () { | |||
|
193 | this._scrollselector = new scrollmanager.ScrollSelector(this.element, this.notebook); | |||
|
194 | }; | |||
|
195 | ||||
|
196 | ||||
190 | MainToolBar.prototype.bind_events = function () { |
|
197 | MainToolBar.prototype.bind_events = function () { | |
191 | var that = this; |
|
198 | var that = this; | |
192 |
|
199 |
@@ -18,6 +18,7 define([ | |||||
18 | 'notebook/js/celltoolbarpresets/default', |
|
18 | 'notebook/js/celltoolbarpresets/default', | |
19 | 'notebook/js/celltoolbarpresets/rawcell', |
|
19 | 'notebook/js/celltoolbarpresets/rawcell', | |
20 | 'notebook/js/celltoolbarpresets/slideshow', |
|
20 | 'notebook/js/celltoolbarpresets/slideshow', | |
|
21 | 'notebook/js/scrollmanager' | |||
21 | ], function ( |
|
22 | ], function ( | |
22 | IPython, |
|
23 | IPython, | |
23 | $, |
|
24 | $, | |
@@ -34,7 +35,8 define([ | |||||
34 | tooltip, |
|
35 | tooltip, | |
35 | default_celltoolbar, |
|
36 | default_celltoolbar, | |
36 | rawcell_celltoolbar, |
|
37 | rawcell_celltoolbar, | |
37 | slideshow_celltoolbar |
|
38 | slideshow_celltoolbar, | |
|
39 | scrollmanager | |||
38 | ) { |
|
40 | ) { | |
39 |
|
41 | |||
40 | var Notebook = function (selector, options) { |
|
42 | var Notebook = function (selector, options) { | |
@@ -64,6 +66,9 define([ | |||||
64 | this.ws_url = options.ws_url; |
|
66 | this.ws_url = options.ws_url; | |
65 | this._session_starting = false; |
|
67 | this._session_starting = false; | |
66 | this.default_cell_type = this.config.default_cell_type || 'code'; |
|
68 | this.default_cell_type = this.config.default_cell_type || 'code'; | |
|
69 | ||||
|
70 | // Create and register scroll managers. | |||
|
71 | this.scrollmanager = new scrollmanager.ScrollManager(this); | |||
67 | // default_kernel_name is a temporary measure while we implement proper |
|
72 | // default_kernel_name is a temporary measure while we implement proper | |
68 | // kernel selection and delayed start. Do not rely on it. |
|
73 | // kernel selection and delayed start. Do not rely on it. | |
69 | this.default_kernel_name = 'python'; |
|
74 | this.default_kernel_name = 'python'; | |
@@ -135,7 +140,7 define([ | |||||
135 | rawcell_celltoolbar.register(this); |
|
140 | rawcell_celltoolbar.register(this); | |
136 | slideshow_celltoolbar.register(this); |
|
141 | slideshow_celltoolbar.register(this); | |
137 | }; |
|
142 | }; | |
138 |
|
143 | |||
139 | Notebook.options_default = { |
|
144 | Notebook.options_default = { | |
140 | // can be any cell type, or the special values of |
|
145 | // can be any cell type, or the special values of | |
141 | // 'above', 'below', or 'selected' to get the value from another cell. |
|
146 | // 'above', 'below', or 'selected' to get the value from another cell. |
@@ -1,9 +1,51 | |||||
1 | // Copyright (c) IPython Development Team. |
|
1 | // Copyright (c) IPython Development Team. | |
2 | // Distributed under the terms of the Modified BSD License. |
|
2 | // Distributed under the terms of the Modified BSD License. | |
3 | define([], function(){ |
|
3 | define(['jquery'], function($){ | |
4 | "use strict"; |
|
4 | "use strict"; | |
5 |
|
5 | |||
6 |
var Scroll |
|
6 | var ScrollSelector = function(element, notebook) { | |
|
7 | // Public constructor. | |||
|
8 | this.notebook = notebook; | |||
|
9 | $('<span />') | |||
|
10 | .addClass('nabar-text') | |||
|
11 | .text('Scrolling Mode:') | |||
|
12 | .appendTo(element); | |||
|
13 | this._combo = $('<select />') | |||
|
14 | .addClass('form-control select-xs') | |||
|
15 | .appendTo(element); | |||
|
16 | ||||
|
17 | // Redirect class level manager registration to this instance. | |||
|
18 | this._registered = {}; | |||
|
19 | ScrollSelector.register = $.proxy(this.register, this); | |||
|
20 | ||||
|
21 | // Register cached managers. | |||
|
22 | for (var i =0; i < ScrollSelector.registered.length; i++) { | |||
|
23 | this.register.apply(this, ScrollSelector.registered[i]); | |||
|
24 | } | |||
|
25 | ||||
|
26 | // Listen for scroll manager change, apply it to the notebook. | |||
|
27 | var that = this; | |||
|
28 | this._combo.change(function(){ | |||
|
29 | var manager = that._registered[$(this).find("option:selected").val()]; | |||
|
30 | that.notebook.ScrollSelector = manager; | |||
|
31 | }); | |||
|
32 | }; | |||
|
33 | ||||
|
34 | // Cache scroll managers registered before the construction of a scroll | |||
|
35 | // manager. | |||
|
36 | ScrollSelector.registered = []; | |||
|
37 | ScrollSelector.register = function(name, manager) { | |||
|
38 | ScrollSelector.registered.push(arguments); | |||
|
39 | }; | |||
|
40 | ScrollSelector.prototype.register = function(name, manager) { | |||
|
41 | this._registered[name] = manager; | |||
|
42 | this._combo.append($('<option />') | |||
|
43 | .val(name) | |||
|
44 | .text(name)); | |||
|
45 | }; | |||
|
46 | ||||
|
47 | ||||
|
48 | var ScrollManager = function(notebook) { | |||
7 | // Public constructor. |
|
49 | // Public constructor. | |
8 | this.notebook = notebook; |
|
50 | this.notebook = notebook; | |
9 | this.animation_speed = 250; //ms |
|
51 | this.animation_speed = 250; //ms | |
@@ -16,6 +58,62 define([], function(){ | |||||
16 | // ---------- |
|
58 | // ---------- | |
17 | // delta: integer |
|
59 | // delta: integer | |
18 | // direction to scroll the document. Positive is downwards. |
|
60 | // direction to scroll the document. Positive is downwards. | |
|
61 | this.scroll_some(delta); | |||
|
62 | return false; | |||
|
63 | }; | |||
|
64 | ||||
|
65 | ScrollManager.prototype.scroll_to = function(destination) { | |||
|
66 | // Scroll to an element in the notebook. | |||
|
67 | $('#notebook').animate({'scrollTop': $(destination).offset().top + $('#notebook').scrollTop() - $('#notebook').offset().top}, this.animation_speed); | |||
|
68 | }; | |||
|
69 | ||||
|
70 | ScrollManager.prototype.scroll_some = function(pages) { | |||
|
71 | // Scroll up or down a given number of pages. | |||
|
72 | $('#notebook').animate({'scrollTop': $('#notebook').scrollTop() + pages * $('#notebook').height()}, this.animation_speed); | |||
|
73 | }; | |||
|
74 | ||||
|
75 | ScrollManager.prototype.get_first_visible_cell = function() { | |||
|
76 | // Gets the index of the first visible cell in the document. | |||
|
77 | ||||
|
78 | // First, attempt to be smart by guessing the index of the cell we are | |||
|
79 | // scrolled to. Then, walk from there up or down until the right cell | |||
|
80 | // is found. To guess the index, get the top of the last cell, and | |||
|
81 | // divide that by the number of cells to get an average cell height. | |||
|
82 | // Then divide the scroll height by the average cell height. | |||
|
83 | var cell_count = that.notebook.ncells(); | |||
|
84 | var first_cell_top = that.notebook.get_cell(0).element.offset.top(); | |||
|
85 | var last_cell_top = that.notebook.get_cell(cell_count-1).element.offset.top(); | |||
|
86 | var avg_cell_height = (last_cell_top - first_cell_top) / cell_count; | |||
|
87 | var $notebook = $('#notebook').scrollTop(); | |||
|
88 | var i = Math.ceil($notebook.scrollTop() / avg_cell_height); | |||
|
89 | i = min(max(i , 0), cell_count - 1); | |||
|
90 | ||||
|
91 | while (that.notebook.get_cell(i).element.offset.top() - first_cell_top < $notebook.scrollTop() && i < cell_count - 1) { | |||
|
92 | i += 1; | |||
|
93 | } | |||
|
94 | ||||
|
95 | while (that.notebook.get_cell(i).element.offset.top() - first_cell_top > $notebook.scrollTop() && i >= 0) { | |||
|
96 | i -= 1; | |||
|
97 | } | |||
|
98 | return min(i + 1, cell_count - 1); | |||
|
99 | }; | |||
|
100 | ||||
|
101 | ||||
|
102 | var HeadingScrollManager = function(notebook, heading_level) { | |||
|
103 | // Public constructor. | |||
|
104 | }; | |||
|
105 | ||||
|
106 | ||||
|
107 | var SlideScrollManager = function(notebook) { | |||
|
108 | // Public constructor. | |||
|
109 | }; | |||
|
110 | ||||
|
111 | /*// Scroll the document. | |||
|
112 | // | |||
|
113 | // Parameters | |||
|
114 | // ---------- | |||
|
115 | // delta: integer | |||
|
116 | // direction to scroll the document. Positive is downwards. | |||
19 |
|
117 | |||
20 | // If one or more slides exist, scroll to the slide. |
|
118 | // If one or more slides exist, scroll to the slide. | |
21 | var $slide_cells = $('.slideshow-slide'); |
|
119 | var $slide_cells = $('.slideshow-slide'); | |
@@ -66,19 +164,13 define([], function(){ | |||||
66 | } else { |
|
164 | } else { | |
67 | this.scroll_some(delta); |
|
165 | this.scroll_some(delta); | |
68 | return false; |
|
166 | return false; | |
69 | } |
|
167 | }*/ | |
70 | }; |
|
|||
71 |
|
||||
72 | ScrollManager.prototype.scroll_to = function(destination) { |
|
|||
73 | // Scroll to an element in the notebook. |
|
|||
74 | $('#notebook').animate({'scrollTop': $(destination).offset().top + $('#notebook').scrollTop() - $('#notebook').offset().top}, this.animation_speed); |
|
|||
75 | }; |
|
|||
76 |
|
||||
77 | ScrollManager.prototype.scroll_some = function(pages) { |
|
|||
78 | // Scroll up or down a given number of pages. |
|
|||
79 | $('#notebook').animate({'scrollTop': $('#notebook').scrollTop() + pages * $('#notebook').height()}, this.animation_speed); |
|
|||
80 | }; |
|
|||
81 |
|
168 | |||
82 | // Return naemspace for require.js loads |
|
169 | // Return naemspace for require.js loads | |
83 | return ScrollManager; |
|
170 | return { | |
|
171 | 'ScrollSelector': ScrollSelector, | |||
|
172 | 'ScrollManager': ScrollManager, | |||
|
173 | 'SlideScrollManager': SlideScrollManager, | |||
|
174 | 'HeadingScrollManager': HeadingScrollManager | |||
|
175 | }; | |||
84 | }); |
|
176 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now