Show More
@@ -27,7 +27,7 var IPython = (function (IPython) { | |||||
27 | '1 !': 49, '2 @': 50, '3 #': 51, '4 $': 52, '5 %': 53, '6 ^': 54, |
|
27 | '1 !': 49, '2 @': 50, '3 #': 51, '4 $': 52, '5 %': 53, '6 ^': 54, | |
28 | '7 &': 55, '8 *': 56, '9 (': 57, '0 )': 48, |
|
28 | '7 &': 55, '8 *': 56, '9 (': 57, '0 )': 48, | |
29 | '[ {': 219, '] }': 221, '` ~': 192, ', <': 188, '. >': 190, '/ ?': 191, |
|
29 | '[ {': 219, '] }': 221, '` ~': 192, ', <': 188, '. >': 190, '/ ?': 191, | |
30 |
'\\ |': 220 |
|
30 | '\\ |': 220, '\' "': 222, | |
31 | 'numpad0': 96, 'numpad1': 97, 'numpad2': 98, 'numpad3': 99, 'numpad4': 100, |
|
31 | 'numpad0': 96, 'numpad1': 97, 'numpad2': 98, 'numpad3': 99, 'numpad4': 100, | |
32 | 'numpad5': 101, 'numpad6': 102, 'numpad7': 103, 'numpad8': 104, 'numpad9': 105, |
|
32 | 'numpad5': 101, 'numpad6': 102, 'numpad7': 103, 'numpad8': 104, 'numpad9': 105, | |
33 | 'multiply': 106, 'add': 107, 'subtract': 109, 'decimal': 110, 'divide': 111, |
|
33 | 'multiply': 106, 'add': 107, 'subtract': 109, 'decimal': 110, 'divide': 111, | |
@@ -41,12 +41,12 var IPython = (function (IPython) { | |||||
41 |
|
41 | |||
42 | // These apply to Firefox and Opera |
|
42 | // These apply to Firefox and Opera | |
43 | var _mozilla_keycodes = { |
|
43 | var _mozilla_keycodes = { | |
44 | '; :': 59, '= +': 61 |
|
44 | '; :': 59, '= +': 61, '- _': 109, | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | // This apply to Webkit and IE |
|
47 | // This apply to Webkit and IE | |
48 | var _ie_keycodes = { |
|
48 | var _ie_keycodes = { | |
49 | '; :': 186, '= +': 187, |
|
49 | '; :': 186, '= +': 187, '- _': 189, | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | var browser = IPython.utils.browser[0]; |
|
52 | var browser = IPython.utils.browser[0]; | |
@@ -60,20 +60,17 var IPython = (function (IPython) { | |||||
60 | var keycodes = {}; |
|
60 | var keycodes = {}; | |
61 | var inv_keycodes = {}; |
|
61 | var inv_keycodes = {}; | |
62 | for (var name in _keycodes) { |
|
62 | for (var name in _keycodes) { | |
63 | console.log(name); |
|
|||
64 | var names = name.split(' '); |
|
63 | var names = name.split(' '); | |
65 | if (names.length === 1) { |
|
64 | if (names.length === 1) { | |
66 | var n = names[0] |
|
65 | var n = names[0] | |
67 | keycodes[n] = _keycodes[n] |
|
66 | keycodes[n] = _keycodes[n] | |
68 | inv_keycodes[_keycodes[n]] = n |
|
67 | inv_keycodes[_keycodes[n]] = n | |
69 | // console.log(keycodes[n], inv_keycodes[_keycodes[n]]); |
|
|||
70 | } else { |
|
68 | } else { | |
71 | var primary = names[0]; |
|
69 | var primary = names[0]; | |
72 | var secondary = names[1]; |
|
70 | var secondary = names[1]; | |
73 | keycodes[primary] = _keycodes[name] |
|
71 | keycodes[primary] = _keycodes[name] | |
74 | keycodes[secondary] = _keycodes[name] |
|
72 | keycodes[secondary] = _keycodes[name] | |
75 | inv_keycodes[_keycodes[name]] = primary |
|
73 | inv_keycodes[_keycodes[name]] = primary | |
76 | // console.log(keycodes[primary], keycodes[secondary], inv_keycodes[_keycodes[name]]) |
|
|||
77 | } |
|
74 | } | |
78 | } |
|
75 | } | |
79 |
|
76 | |||
@@ -210,21 +207,21 var IPython = (function (IPython) { | |||||
210 | 'x' : { |
|
207 | 'x' : { | |
211 | help : 'cut cell', |
|
208 | help : 'cut cell', | |
212 | handler : function (event) { |
|
209 | handler : function (event) { | |
213 |
|
|
210 | IPython.notebook.cut_cell(); | |
214 | return false; |
|
211 | return false; | |
215 | } |
|
212 | } | |
216 | }, |
|
213 | }, | |
217 | 'c' : { |
|
214 | 'c' : { | |
218 | help : 'copy cell', |
|
215 | help : 'copy cell', | |
219 | handler : function (event) { |
|
216 | handler : function (event) { | |
220 |
|
|
217 | IPython.notebook.copy_cell(); | |
221 | return false; |
|
218 | return false; | |
222 | } |
|
219 | } | |
223 | }, |
|
220 | }, | |
224 | 'v' : { |
|
221 | 'v' : { | |
225 | help : 'paste cell below', |
|
222 | help : 'paste cell below', | |
226 | handler : function (event) { |
|
223 | handler : function (event) { | |
227 |
|
|
224 | IPython.notebook.paste_cell_below(); | |
228 | return false; |
|
225 | return false; | |
229 | } |
|
226 | } | |
230 | }, |
|
227 | }, | |
@@ -232,7 +229,6 var IPython = (function (IPython) { | |||||
232 | help : 'delete cell (press twice)', |
|
229 | help : 'delete cell (press twice)', | |
233 | handler : function (event) { |
|
230 | handler : function (event) { | |
234 | var dc = IPython.delete_count; |
|
231 | var dc = IPython.delete_count; | |
235 | console.log('delete_count', dc); |
|
|||
236 | if (dc === undefined) { |
|
232 | if (dc === undefined) { | |
237 | IPython.delete_count = 0; |
|
233 | IPython.delete_count = 0; | |
238 | } else if (dc === 0) { |
|
234 | } else if (dc === 0) { | |
@@ -419,6 +415,14 var IPython = (function (IPython) { | |||||
419 | this._shortcuts = {} |
|
415 | this._shortcuts = {} | |
420 | } |
|
416 | } | |
421 |
|
417 | |||
|
418 | ShortcutManager.prototype.help = function () { | |||
|
419 | var help = []; | |||
|
420 | for (var shortcut in this._shortcuts) { | |||
|
421 | help.push({shortcut: shortcut, help: this._shortcuts[shortcut]['help']}); | |||
|
422 | } | |||
|
423 | return help; | |||
|
424 | } | |||
|
425 | ||||
422 | ShortcutManager.prototype.canonicalize_key = function (key) { |
|
426 | ShortcutManager.prototype.canonicalize_key = function (key) { | |
423 | return inv_keycodes[keycodes[key]]; |
|
427 | return inv_keycodes[keycodes[key]]; | |
424 | } |
|
428 | } | |
@@ -430,7 +434,7 var IPython = (function (IPython) { | |||||
430 | return this.canonicalize_key(values[0]) |
|
434 | return this.canonicalize_key(values[0]) | |
431 | } else { |
|
435 | } else { | |
432 | var modifiers = values.slice(0,-1); |
|
436 | var modifiers = values.slice(0,-1); | |
433 | var key = this.canonicalize_key(values[-1]); |
|
437 | var key = this.canonicalize_key(values[values.length-1]); | |
434 | modifiers.sort(); |
|
438 | modifiers.sort(); | |
435 | return modifiers.join('+') + '+' + key; |
|
439 | return modifiers.join('+') + '+' + key; | |
436 | } |
|
440 | } | |
@@ -472,7 +476,6 var IPython = (function (IPython) { | |||||
472 | var shortcut = this.event_to_shortcut(event); |
|
476 | var shortcut = this.event_to_shortcut(event); | |
473 | var data = this._shortcuts[shortcut]; |
|
477 | var data = this._shortcuts[shortcut]; | |
474 | if (data !== undefined) { |
|
478 | if (data !== undefined) { | |
475 | console.log('call_handler', shortcut, data['help']); |
|
|||
476 | var handler = data['handler']; |
|
479 | var handler = data['handler']; | |
477 | if (handler !== undefined) { |
|
480 | if (handler !== undefined) { | |
478 | return handler(event); |
|
481 | return handler(event); |
@@ -23,44 +23,42 var IPython = (function (IPython) { | |||||
23 | $(this.shortcut_dialog).modal("toggle"); |
|
23 | $(this.shortcut_dialog).modal("toggle"); | |
24 | return; |
|
24 | return; | |
25 | } |
|
25 | } | |
26 | var body = $('<div/>'); |
|
26 | var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help(); | |
27 | var shortcuts = [ |
|
27 | var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help(); | |
28 | {key: 'Shift-Enter', help: 'run cell'}, |
|
28 | var help, shortcut; | |
29 | {key: 'Ctrl-Enter', help: 'run cell in-place'}, |
|
29 | var element = $('<div/>'); | |
30 | {key: 'Alt-Enter', help: 'run cell, insert below'}, |
|
30 | ||
31 | {key: 'Ctrl-m x', help: 'cut cell'}, |
|
31 | // Command mode | |
32 | {key: 'Ctrl-m c', help: 'copy cell'}, |
|
32 | var cmd_div = $('<div/>').addClass('clearfix').append($('<h4>Command Mode</h4>')); | |
33 | {key: 'Ctrl-m v', help: 'paste cell'}, |
|
33 | element.append(cmd_div); | |
34 | {key: 'Ctrl-m d', help: 'delete cell'}, |
|
34 | for (var i=0; i<command_shortcuts.length; i++) { | |
35 | {key: 'Ctrl-m z', help: 'undo last cell deletion'}, |
|
35 | help = command_shortcuts[i]['help']; | |
36 | {key: 'Ctrl-m -', help: 'split cell'}, |
|
36 | shortcut = command_shortcuts[i]['shortcut']; | |
37 | {key: 'Ctrl-m a', help: 'insert cell above'}, |
|
37 | if (help) { | |
38 | {key: 'Ctrl-m b', help: 'insert cell below'}, |
|
38 | cmd_div.append($('<div>').addClass('quickhelp'). | |
39 | {key: 'Ctrl-m o', help: 'toggle output'}, |
|
39 | append($('<span/>').addClass('shortcut_key').html(shortcut)). | |
40 | {key: 'Ctrl-m O', help: 'toggle output scroll'}, |
|
40 | append($('<span/>').addClass('shortcut_descr').html(' : ' + help)) | |
41 | {key: 'Ctrl-m l', help: 'toggle line numbers'}, |
|
41 | ); | |
42 | {key: 'Ctrl-m s', help: 'save notebook'}, |
|
42 | } | |
43 | {key: 'Ctrl-m j', help: 'move cell down'}, |
|
43 | }; | |
44 | {key: 'Ctrl-m k', help: 'move cell up'}, |
|
44 | ||
45 | {key: 'Ctrl-m y', help: 'code cell'}, |
|
45 | // Edit mode | |
46 | {key: 'Ctrl-m m', help: 'markdown cell'}, |
|
46 | var edit_div = $('<div/>').addClass('clearfix').append($('<h4>Edit Mode</h4>')); | |
47 | {key: 'Ctrl-m t', help: 'raw cell'}, |
|
47 | element.append(edit_div); | |
48 | {key: 'Ctrl-m 1-6', help: 'heading 1-6 cell'}, |
|
48 | for (var i=0; i<edit_shortcuts.length; i++) { | |
49 | {key: 'Ctrl-m p', help: 'select previous'}, |
|
49 | help = edit_shortcuts[i]['help']; | |
50 | {key: 'Ctrl-m n', help: 'select next'}, |
|
50 | shortcut = edit_shortcuts[i]['shortcut']; | |
51 | {key: 'Ctrl-m i', help: 'interrupt kernel'}, |
|
51 | if (help) { | |
52 | {key: 'Ctrl-m .', help: 'restart kernel'}, |
|
52 | edit_div.append($('<div>').addClass('quickhelp'). | |
53 | {key: 'Ctrl-m h', help: 'show keyboard shortcuts'} |
|
53 | append($('<span/>').addClass('shortcut_key').html(shortcut)). | |
54 | ]; |
|
54 | append($('<span/>').addClass('shortcut_descr').html(' : ' + help)) | |
55 | for (var i=0; i<shortcuts.length; i++) { |
|
55 | ); | |
56 | body.append($('<div>').addClass('quickhelp'). |
|
56 | } | |
57 | append($('<span/>').addClass('shortcut_key').html(shortcuts[i].key)). |
|
|||
58 | append($('<span/>').addClass('shortcut_descr').html(' : ' + shortcuts[i].help)) |
|
|||
59 | ); |
|
|||
60 | }; |
|
57 | }; | |
|
58 | ||||
61 | this.shortcut_dialog = IPython.dialog.modal({ |
|
59 | this.shortcut_dialog = IPython.dialog.modal({ | |
62 | title : "Keyboard shortcuts", |
|
60 | title : "Keyboard shortcuts", | |
63 |
body : |
|
61 | body : element, | |
64 | destroy : false, |
|
62 | destroy : false, | |
65 | buttons : { |
|
63 | buttons : { | |
66 | Close : {} |
|
64 | Close : {} |
General Comments 0
You need to be logged in to leave comments.
Login now