Show More
@@ -85,25 +85,25 IPython.keyboard = (function (IPython) { | |||||
85 | // Put a shortcut into normalized form: |
|
85 | // Put a shortcut into normalized form: | |
86 | // 1. Make lowercase |
|
86 | // 1. Make lowercase | |
87 | // 2. Replace cmd by meta |
|
87 | // 2. Replace cmd by meta | |
88 |
// 3. Sort ' |
|
88 | // 3. Sort '-' separated modifiers into the order alt-ctrl-meta-shift | |
89 | // 4. Normalize keys |
|
89 | // 4. Normalize keys | |
90 | shortcut = shortcut.toLowerCase().replace('cmd', 'meta'); |
|
90 | shortcut = shortcut.toLowerCase().replace('cmd', 'meta'); | |
91 |
var values = shortcut.split(" |
|
91 | var values = shortcut.split("-"); | |
92 | if (values.length === 1) { |
|
92 | if (values.length === 1) { | |
93 | return normalize_key(values[0]); |
|
93 | return normalize_key(values[0]); | |
94 | } else { |
|
94 | } else { | |
95 | var modifiers = values.slice(0,-1); |
|
95 | var modifiers = values.slice(0,-1); | |
96 | var key = normalize_key(values[values.length-1]); |
|
96 | var key = normalize_key(values[values.length-1]); | |
97 | modifiers.sort(); |
|
97 | modifiers.sort(); | |
98 |
return modifiers.join(' |
|
98 | return modifiers.join('-') + '-' + key; | |
99 | } |
|
99 | } | |
100 | }; |
|
100 | }; | |
101 |
|
101 | |||
102 | var shortcut_to_event = function (shortcut, type) { |
|
102 | var shortcut_to_event = function (shortcut, type) { | |
103 |
// Convert a shortcut (shift |
|
103 | // Convert a shortcut (shift-r) to a jQuery Event object | |
104 | type = type || 'keydown'; |
|
104 | type = type || 'keydown'; | |
105 | shortcut = normalize_shortcut(shortcut); |
|
105 | shortcut = normalize_shortcut(shortcut); | |
106 |
var values = shortcut.split(" |
|
106 | var values = shortcut.split("-"); | |
107 | var modifiers = values.slice(0,-1); |
|
107 | var modifiers = values.slice(0,-1); | |
108 | var key = values[values.length-1]; |
|
108 | var key = values[values.length-1]; | |
109 | var opts = {which: keycodes[key]}; |
|
109 | var opts = {which: keycodes[key]}; | |
@@ -115,13 +115,13 IPython.keyboard = (function (IPython) { | |||||
115 | }; |
|
115 | }; | |
116 |
|
116 | |||
117 | var event_to_shortcut = function (event) { |
|
117 | var event_to_shortcut = function (event) { | |
118 |
// Convert a jQuery Event object to a shortcut (shift |
|
118 | // Convert a jQuery Event object to a shortcut (shift-r) | |
119 | var shortcut = ''; |
|
119 | var shortcut = ''; | |
120 | var key = inv_keycodes[event.which]; |
|
120 | var key = inv_keycodes[event.which]; | |
121 |
if (event.altKey && key !== 'alt') {shortcut += 'alt |
|
121 | if (event.altKey && key !== 'alt') {shortcut += 'alt-';} | |
122 |
if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl |
|
122 | if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl-';} | |
123 |
if (event.metaKey && key !== 'meta') {shortcut += 'meta |
|
123 | if (event.metaKey && key !== 'meta') {shortcut += 'meta-';} | |
124 |
if (event.shiftKey && key !== 'shift') {shortcut += 'shift |
|
124 | if (event.shiftKey && key !== 'shift') {shortcut += 'shift-';} | |
125 | shortcut += key; |
|
125 | shortcut += key; | |
126 | return shortcut; |
|
126 | return shortcut; | |
127 | }; |
|
127 | }; |
@@ -26,7 +26,7 var IPython = (function (IPython) { | |||||
26 | return true; |
|
26 | return true; | |
27 | } |
|
27 | } | |
28 | }, |
|
28 | }, | |
29 |
'shift |
|
29 | 'shift-enter' : { | |
30 | help : 'run cell, select below', |
|
30 | help : 'run cell, select below', | |
31 | help_index : 'ba', |
|
31 | help_index : 'ba', | |
32 | handler : function (event) { |
|
32 | handler : function (event) { | |
@@ -34,7 +34,7 var IPython = (function (IPython) { | |||||
34 | return false; |
|
34 | return false; | |
35 | } |
|
35 | } | |
36 | }, |
|
36 | }, | |
37 |
'ctrl |
|
37 | 'ctrl-enter' : { | |
38 | help : 'run cell', |
|
38 | help : 'run cell', | |
39 | help_index : 'bb', |
|
39 | help_index : 'bb', | |
40 | handler : function (event) { |
|
40 | handler : function (event) { | |
@@ -42,7 +42,7 var IPython = (function (IPython) { | |||||
42 | return false; |
|
42 | return false; | |
43 | } |
|
43 | } | |
44 | }, |
|
44 | }, | |
45 |
'alt |
|
45 | 'alt-enter' : { | |
46 | help : 'run cell, insert below', |
|
46 | help : 'run cell, insert below', | |
47 | help_index : 'bc', |
|
47 | help_index : 'bc', | |
48 | handler : function (event) { |
|
48 | handler : function (event) { | |
@@ -64,7 +64,7 var IPython = (function (IPython) { | |||||
64 | } |
|
64 | } | |
65 | }; |
|
65 | }; | |
66 | } else { |
|
66 | } else { | |
67 |
default_common_shortcuts['ctrl |
|
67 | default_common_shortcuts['ctrl-s'] = | |
68 | { |
|
68 | { | |
69 | help : 'save notebook', |
|
69 | help : 'save notebook', | |
70 | help_index : 'fb', |
|
70 | help_index : 'fb', | |
@@ -87,7 +87,7 var IPython = (function (IPython) { | |||||
87 | return false; |
|
87 | return false; | |
88 | } |
|
88 | } | |
89 | }, |
|
89 | }, | |
90 |
'ctrl |
|
90 | 'ctrl-m' : { | |
91 | help : 'command mode', |
|
91 | help : 'command mode', | |
92 | help_index : 'ab', |
|
92 | help_index : 'ab', | |
93 | handler : function (event) { |
|
93 | handler : function (event) { | |
@@ -129,7 +129,7 var IPython = (function (IPython) { | |||||
129 | } |
|
129 | } | |
130 | } |
|
130 | } | |
131 | }, |
|
131 | }, | |
132 |
'alt |
|
132 | 'alt--' : { | |
133 | help : 'split cell', |
|
133 | help : 'split cell', | |
134 | help_index : 'ea', |
|
134 | help_index : 'ea', | |
135 | handler : function (event) { |
|
135 | handler : function (event) { | |
@@ -137,7 +137,7 var IPython = (function (IPython) { | |||||
137 | return false; |
|
137 | return false; | |
138 | } |
|
138 | } | |
139 | }, |
|
139 | }, | |
140 |
'alt |
|
140 | 'alt-subtract' : { | |
141 | help : '', |
|
141 | help : '', | |
142 | help_index : 'eb', |
|
142 | help_index : 'eb', | |
143 | handler : function (event) { |
|
143 | handler : function (event) { | |
@@ -149,7 +149,7 var IPython = (function (IPython) { | |||||
149 | help : 'indent or complete', |
|
149 | help : 'indent or complete', | |
150 | help_index : 'ec', |
|
150 | help_index : 'ec', | |
151 | }, |
|
151 | }, | |
152 |
'shift |
|
152 | 'shift-tab' : { | |
153 | help : 'tooltip', |
|
153 | help : 'tooltip', | |
154 | help_index : 'ed', |
|
154 | help_index : 'ed', | |
155 | }, |
|
155 | }, | |
@@ -172,17 +172,17 var IPython = (function (IPython) { | |||||
172 | help_index : 'eg' |
|
172 | help_index : 'eg' | |
173 | }; |
|
173 | }; | |
174 | } else { |
|
174 | } else { | |
175 |
default_edit_shortcuts['ctrl |
|
175 | default_edit_shortcuts['ctrl-/'] = | |
176 | { |
|
176 | { | |
177 | help : 'toggle comment', |
|
177 | help : 'toggle comment', | |
178 | help_index : 'ee' |
|
178 | help_index : 'ee' | |
179 | }; |
|
179 | }; | |
180 |
default_edit_shortcuts['ctrl |
|
180 | default_edit_shortcuts['ctrl-]'] = | |
181 | { |
|
181 | { | |
182 | help : 'indent', |
|
182 | help : 'indent', | |
183 | help_index : 'ef' |
|
183 | help_index : 'ef' | |
184 | }; |
|
184 | }; | |
185 |
default_edit_shortcuts['ctrl |
|
185 | default_edit_shortcuts['ctrl-['] = | |
186 | { |
|
186 | { | |
187 | help : 'dedent', |
|
187 | help : 'dedent', | |
188 | help_index : 'eg' |
|
188 | help_index : 'eg' | |
@@ -264,7 +264,7 var IPython = (function (IPython) { | |||||
264 | return false; |
|
264 | return false; | |
265 | } |
|
265 | } | |
266 | }, |
|
266 | }, | |
267 |
'shift |
|
267 | 'shift-v' : { | |
268 | help : 'paste cell above', |
|
268 | help : 'paste cell above', | |
269 | help_index : 'eg', |
|
269 | help_index : 'eg', | |
270 | handler : function (event) { |
|
270 | handler : function (event) { | |
@@ -389,7 +389,7 var IPython = (function (IPython) { | |||||
389 | return false; |
|
389 | return false; | |
390 | } |
|
390 | } | |
391 | }, |
|
391 | }, | |
392 |
'shift |
|
392 | 'shift-o' : { | |
393 | help : 'toggle output scrolling', |
|
393 | help : 'toggle output scrolling', | |
394 | help_index : 'gc', |
|
394 | help_index : 'gc', | |
395 | handler : function (event) { |
|
395 | handler : function (event) { | |
@@ -405,7 +405,7 var IPython = (function (IPython) { | |||||
405 | return false; |
|
405 | return false; | |
406 | } |
|
406 | } | |
407 | }, |
|
407 | }, | |
408 |
'ctrl |
|
408 | 'ctrl-j' : { | |
409 | help : 'move cell down', |
|
409 | help : 'move cell down', | |
410 | help_index : 'eb', |
|
410 | help_index : 'eb', | |
411 | handler : function (event) { |
|
411 | handler : function (event) { | |
@@ -413,7 +413,7 var IPython = (function (IPython) { | |||||
413 | return false; |
|
413 | return false; | |
414 | } |
|
414 | } | |
415 | }, |
|
415 | }, | |
416 |
'ctrl |
|
416 | 'ctrl-k' : { | |
417 | help : 'move cell up', |
|
417 | help : 'move cell up', | |
418 | help_index : 'ea', |
|
418 | help_index : 'ea', | |
419 | handler : function (event) { |
|
419 | handler : function (event) { | |
@@ -463,7 +463,7 var IPython = (function (IPython) { | |||||
463 | return false; |
|
463 | return false; | |
464 | } |
|
464 | } | |
465 | }, |
|
465 | }, | |
466 |
'shift |
|
466 | 'shift-m' : { | |
467 | help : 'merge cell below', |
|
467 | help : 'merge cell below', | |
468 | help_index : 'ek', |
|
468 | help_index : 'ek', | |
469 | handler : function (event) { |
|
469 | handler : function (event) { |
@@ -73,7 +73,7 var IPython = (function (IPython) { | |||||
73 |
|
73 | |||
74 | var special_case = { pageup: "PageUp", pagedown: "Page Down" }; |
|
74 | var special_case = { pageup: "PageUp", pagedown: "Page Down" }; | |
75 | var prettify = function (s) { |
|
75 | var prettify = function (s) { | |
76 |
var keys = s.split(' |
|
76 | var keys = s.split('-'); | |
77 | var k, i; |
|
77 | var k, i; | |
78 | for (i in keys) { |
|
78 | for (i in keys) { | |
79 | k = keys[i]; |
|
79 | k = keys[i]; |
@@ -1,13 +1,13 | |||||
1 |
|
1 | |||
2 |
|
2 | |||
3 | var normalized_shortcuts = [ |
|
3 | var normalized_shortcuts = [ | |
4 |
'ctrl |
|
4 | 'ctrl-shift-m', | |
5 |
'alt |
|
5 | 'alt-meta-p', | |
6 | ]; |
|
6 | ]; | |
7 |
|
7 | |||
8 | var to_normalize = [ |
|
8 | var to_normalize = [ | |
9 |
['shift |
|
9 | ['shift-%', 'shift-5'], | |
10 |
['ShiFT |
|
10 | ['ShiFT-MeTa-CtRl-AlT-m', 'alt-ctrl-meta-shift-m'], | |
11 | ]; |
|
11 | ]; | |
12 |
|
12 | |||
13 | var unshifted = "` 1 2 3 4 5 6 7 8 9 0 - = q w e r t y u i o p [ ] \\ a s d f g h j k l ; ' z x c v b n m , . /"; |
|
13 | var unshifted = "` 1 2 3 4 5 6 7 8 9 0 - = q w e r t y u i o p [ ] \\ a s d f g h j k l ; ' z x c v b n m , . /"; | |
@@ -33,7 +33,7 casper.notebook_test(function () { | |||||
33 | }, item); |
|
33 | }, item); | |
34 | this.test.assertEquals(result, item[1], 'Normalize shortcut: '+item[0]); |
|
34 | this.test.assertEquals(result, item[1], 'Normalize shortcut: '+item[0]); | |
35 | }); |
|
35 | }); | |
36 | }) |
|
36 | }); | |
37 |
|
37 | |||
38 | this.then(function () { |
|
38 | this.then(function () { | |
39 | this.each(normalized_shortcuts, function (self, item) { |
|
39 | this.each(normalized_shortcuts, function (self, item) { | |
@@ -46,4 +46,4 casper.notebook_test(function () { | |||||
46 | }); |
|
46 | }); | |
47 | }); |
|
47 | }); | |
48 |
|
48 | |||
49 | }); No newline at end of file |
|
49 | }); |
@@ -22,7 +22,7 casper.notebook_test(function () { | |||||
22 | var cell = IPython.notebook.get_cell(0); |
|
22 | var cell = IPython.notebook.get_cell(0); | |
23 | cell.set_text('a=11; print(a)'); |
|
23 | cell.set_text('a=11; print(a)'); | |
24 | cell.clear_output(); |
|
24 | cell.clear_output(); | |
25 |
IPython.keyboard.trigger_keydown('shift |
|
25 | IPython.keyboard.trigger_keydown('shift-enter'); | |
26 | }); |
|
26 | }); | |
27 |
|
27 | |||
28 | this.wait_for_output(0); |
|
28 | this.wait_for_output(0); | |
@@ -41,7 +41,7 casper.notebook_test(function () { | |||||
41 | var cell = IPython.notebook.get_cell(0); |
|
41 | var cell = IPython.notebook.get_cell(0); | |
42 | cell.set_text('a=12; print(a)'); |
|
42 | cell.set_text('a=12; print(a)'); | |
43 | cell.clear_output(); |
|
43 | cell.clear_output(); | |
44 |
IPython.keyboard.trigger_keydown('ctrl |
|
44 | IPython.keyboard.trigger_keydown('ctrl-enter'); | |
45 | }); |
|
45 | }); | |
46 |
|
46 | |||
47 | this.wait_for_output(0); |
|
47 | this.wait_for_output(0); |
General Comments 0
You need to be logged in to leave comments.
Login now