##// END OF EJS Templates
Removing old keyboard handling from IPython.utils.
Brian E. Granger -
Show More
@@ -350,66 +350,6 b' IPython.utils = (function (IPython) {'
350 350 "$1<a target=\"_blank\" href=\"$2$3\">$2$3</a>");
351 351 }
352 352
353 // some keycodes that seem to be platform/browser independent
354 var keycodes = {
355 BACKSPACE: 8,
356 TAB : 9,
357 ENTER : 13,
358 SHIFT : 16,
359 CTRL : 17,
360 CONTROL : 17,
361 ALT : 18,
362 CAPS_LOCK: 20,
363 ESC : 27,
364 SPACE : 32,
365 PGUP : 33,
366 PGDOWN : 34,
367 END : 35,
368 HOME : 36,
369 LEFT_ARROW: 37,
370 LEFTARROW: 37,
371 LEFT : 37,
372 UP_ARROW : 38,
373 UPARROW : 38,
374 UP : 38,
375 RIGHT_ARROW:39,
376 RIGHTARROW:39,
377 RIGHT : 39,
378 DOWN_ARROW: 40,
379 DOWNARROW: 40,
380 DOWN : 40,
381 I : 73,
382 M : 77,
383 // all three of these keys may be COMMAND on OS X:
384 LEFT_SUPER : 91,
385 RIGHT_SUPER : 92,
386 COMMAND : 93,
387 };
388
389 // trigger a key press event
390 var press = function (key) {
391 var key_press = $.Event('keydown', {which: key});
392 $(document).trigger(key_press);
393 }
394
395 var press_up = function() { press(keycodes.UP); };
396 var press_down = function() { press(keycodes.DOWN); };
397
398 var press_ctrl_enter = function() {
399 $(document).trigger($.Event('keydown', {which: keycodes.ENTER, ctrlKey: true}));
400 };
401
402 var press_shift_enter = function() {
403 $(document).trigger($.Event('keydown', {which: keycodes.ENTER, shiftKey: true}));
404 };
405
406 // trigger the ctrl-m shortcut followed by one of our keys
407 var press_ghetto = function(key) {
408 $(document).trigger($.Event('keydown', {which: keycodes.M, ctrlKey: true}));
409 press(key);
410 };
411
412
413 353 var points_to_pixels = function (points) {
414 354 // A reasonably good way of converting between points and pixels.
415 355 var test = $('<div style="display: none; width: 10000pt; padding:0; border:0;"></div>');
@@ -431,7 +371,6 b' IPython.utils = (function (IPython) {'
431 371 };
432 372 };
433 373
434
435 374 var url_path_join = function () {
436 375 // join a sequence of url components with '/'
437 376 var url = '';
@@ -554,13 +493,6 b' IPython.utils = (function (IPython) {'
554 493 regex_split : regex_split,
555 494 uuid : uuid,
556 495 fixConsole : fixConsole,
557 keycodes : keycodes,
558 press : press,
559 press_up : press_up,
560 press_down : press_down,
561 press_ctrl_enter : press_ctrl_enter,
562 press_shift_enter : press_shift_enter,
563 press_ghetto : press_ghetto,
564 496 fixCarriageReturn : fixCarriageReturn,
565 497 autoLinkUrls : autoLinkUrls,
566 498 points_to_pixels : points_to_pixels,
@@ -14,7 +14,6 b''
14 14
15 15 var CellToolbar = IPython.CellToolbar;
16 16 var raw_cell_preset = [];
17 var utils = IPython.utils;
18 17
19 18 var select_type = CellToolbar.utils.select_ui_generator([
20 19 ["None", "-"],
@@ -58,7 +57,7 b''
58 57 var that = $(this);
59 58 // Upon ENTER, click the OK button.
60 59 that.find('input[type="text"]').keydown(function (event, ui) {
61 if (event.which === utils.keycodes.ENTER) {
60 if (event.which === IPython.keyboard.keycodes.enter) {
62 61 that.find('.btn-primary').first().click();
63 62 return false;
64 63 }
@@ -45,7 +45,7 b' var IPython = (function (IPython) {'
45 45 "use strict";
46 46
47 47 var utils = IPython.utils;
48 var key = IPython.utils.keycodes;
48 var keycodes = IPython.keyboard.keycodes;
49 49
50 50 /**
51 51 * A Cell conceived to write code.
@@ -195,16 +195,16 b' var IPython = (function (IPython) {'
195 195 // whatever key is pressed, first, cancel the tooltip request before
196 196 // they are sent, and remove tooltip if any, except for tab again
197 197 var tooltip_closed = null;
198 if (event.type === 'keydown' && event.which != key.TAB ) {
198 if (event.type === 'keydown' && event.which != keycodes.tab ) {
199 199 tooltip_closed = IPython.tooltip.remove_and_cancel_tooltip();
200 200 }
201 201
202 202 var cur = editor.getCursor();
203 if (event.keyCode === key.ENTER){
203 if (event.keyCode === keycodes.enter){
204 204 this.auto_highlight();
205 205 }
206 206
207 if (event.keyCode === key.ENTER && (event.shiftKey || event.ctrlKey || event.altKey)) {
207 if (event.keyCode === keycodes.enter && (event.shiftKey || event.ctrlKey || event.altKey)) {
208 208 // Always ignore shift-enter in CodeMirror as we handle it.
209 209 return true;
210 210 } else if (event.which === 40 && event.type === 'keypress' && IPython.tooltip.time_before_tooltip >= 0) {
@@ -214,7 +214,7 b' var IPython = (function (IPython) {'
214 214 // The second argument says to hide the tooltip if the docstring
215 215 // is actually empty
216 216 IPython.tooltip.pending(that, true);
217 } else if (event.which === key.UPARROW && event.type === 'keydown') {
217 } else if (event.which === keycodes.up && event.type === 'keydown') {
218 218 // If we are not at the top, let CM handle the up arrow and
219 219 // prevent the global keydown handler from handling it.
220 220 if (!that.at_top()) {
@@ -223,7 +223,7 b' var IPython = (function (IPython) {'
223 223 } else {
224 224 return true;
225 225 }
226 } else if (event.which === key.ESC && event.type === 'keydown') {
226 } else if (event.which === keycodes.esc && event.type === 'keydown') {
227 227 // First see if the tooltip is active and if so cancel it.
228 228 if (tooltip_closed) {
229 229 // The call to remove_and_cancel_tooltip above in L177 doesn't pass
@@ -249,7 +249,7 b' var IPython = (function (IPython) {'
249 249 // Don't let CM handle the event, defer to global handling.
250 250 return true;
251 251 }
252 } else if (event.which === key.DOWNARROW && event.type === 'keydown') {
252 } else if (event.which === keycodes.down && event.type === 'keydown') {
253 253 // If we are not at the bottom, let CM handle the down arrow and
254 254 // prevent the global keydown handler from handling it.
255 255 if (!that.at_bottom()) {
@@ -258,7 +258,7 b' var IPython = (function (IPython) {'
258 258 } else {
259 259 return true;
260 260 }
261 } else if (event.keyCode === key.TAB && event.type === 'keydown' && event.shiftKey) {
261 } else if (event.keyCode === keycodes.tab && event.type === 'keydown' && event.shiftKey) {
262 262 if (editor.somethingSelected()){
263 263 var anchor = editor.getCursor("anchor");
264 264 var head = editor.getCursor("head");
@@ -269,7 +269,7 b' var IPython = (function (IPython) {'
269 269 IPython.tooltip.request(that);
270 270 event.stop();
271 271 return true;
272 } else if (event.keyCode === key.TAB && event.type == 'keydown') {
272 } else if (event.keyCode === keycodes.tab && event.type == 'keydown') {
273 273 // Tab completion.
274 274 IPython.tooltip.remove_and_cancel_tooltip();
275 275 if (editor.somethingSelected()) {
@@ -6,7 +6,7 b' var IPython = (function (IPython) {'
6 6 "use strict";
7 7
8 8 // easier key mapping
9 var key = IPython.utils.keycodes;
9 var keycodes = IPython.keyboard.keycodes;
10 10
11 11 function prepend_n_prc(str, n) {
12 12 for( var i =0 ; i< n ; i++){
@@ -317,19 +317,20 b' var IPython = (function (IPython) {'
317 317 }
318 318
319 319 // Enter
320 if (code == key.ENTER) {
320 if (code == keycodes.enter) {
321 321 CodeMirror.e_stop(event);
322 322 this.pick();
323 323 }
324 324 // Escape or backspace
325 else if (code == key.ESC) {
325 else if (code == keycodes.esc) {
326 326 CodeMirror.e_stop(event);
327 327 this.close();
328 328 this.editor.focus();
329 } else if (code == key.BACKSPACE) {
329
330 } else if (code == keycodes.backspace) {
330 331 this.close();
331 332 this.editor.focus();
332 } else if (code == key.TAB) {
333 } else if (code == keycodes.tab) {
333 334 //all the fastforwarding operation,
334 335 //Check that shared start is not null which can append with prefixed completion
335 336 // like %pylab , pylab have no shred start, and ff will result in py<tab><tab>
@@ -345,7 +346,7 b' var IPython = (function (IPython) {'
345 346 setTimeout(function () {
346 347 that.carry_on_completion();
347 348 }, 50);
348 } else if (code == key.UPARROW || code == key.DOWNARROW) {
349 } else if (code == keycodes.up || code == keycodes.down) {
349 350 // need to do that to be able to move the arrow
350 351 // when on the first or last line ofo a code cell
351 352 event.stopPropagation();
@@ -1917,7 +1917,7 b' var IPython = (function (IPython) {'
1917 1917 var that = $(this);
1918 1918 // Upon ENTER, click the OK button.
1919 1919 that.find('input[type="text"]').keydown(function (event, ui) {
1920 if (event.which === utils.keycodes.ENTER) {
1920 if (event.which === IPython.keyboard.keycodes.enter) {
1921 1921 that.find('.btn-primary').first().click();
1922 1922 }
1923 1923 });
@@ -669,7 +669,7 b' var IPython = (function (IPython) {'
669 669 .keydown(function (event, ui) {
670 670 // make sure we submit on enter,
671 671 // and don't re-execute the *cell* on shift-enter
672 if (event.which === utils.keycodes.ENTER) {
672 if (event.which === IPython.keyboard.keycodes.enter) {
673 673 that._submit_raw_input();
674 674 return false;
675 675 }
@@ -103,7 +103,7 b' var IPython = (function (IPython) {'
103 103 var that = $(this);
104 104 // Upon ENTER, click the OK button.
105 105 that.find('input[type="text"]').keydown(function (event, ui) {
106 if (event.which === utils.keycodes.ENTER) {
106 if (event.which === IPython.keyboard.keycodes.enter) {
107 107 that.find('.btn-primary').first().click();
108 108 return false;
109 109 }
@@ -20,7 +20,7 b' var IPython = (function (IPython) {'
20 20 "use strict";
21 21
22 22 // TextCell base class
23 var key = IPython.utils.keycodes;
23 var keycodes = IPython.keyboard.keycodes;
24 24
25 25 /**
26 26 * Construct a new TextCell, codemirror mode is by default 'htmlmixed', and cell type is 'text'
@@ -140,7 +140,7 b' var IPython = (function (IPython) {'
140 140 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey || event.altKey)) {
141 141 // Always ignore shift-enter in CodeMirror as we handle it.
142 142 return true;
143 } else if (event.which === key.UPARROW && event.type === 'keydown') {
143 } else if (event.which === keycodes.up && event.type === 'keydown') {
144 144 // If we are not at the top, let CM handle the up arrow and
145 145 // prevent the global keydown handler from handling it.
146 146 if (!that.at_top()) {
@@ -148,8 +148,8 b' var IPython = (function (IPython) {'
148 148 return false;
149 149 } else {
150 150 return true;
151 }
152 } else if (event.which === key.DOWNARROW && event.type === 'keydown') {
151 };
152 } else if (event.which === keycodes.down && event.type === 'keydown') {
153 153 // If we are not at the bottom, let CM handle the down arrow and
154 154 // prevent the global keydown handler from handling it.
155 155 if (!that.at_bottom()) {
@@ -157,8 +157,8 b' var IPython = (function (IPython) {'
157 157 return false;
158 158 } else {
159 159 return true;
160 }
161 } else if (event.which === key.ESC && event.type === 'keydown') {
160 };
161 } else if (event.which === keycodes.esc && event.type === 'keydown') {
162 162 if (that.code_mirror.options.keyMap === "vim-insert") {
163 163 // vim keyMap is active and in insert mode. In this case we leave vim
164 164 // insert mode, but remain in notebook edit mode.
@@ -5,14 +5,14 b' casper.notebook_test(function () {'
5 5 var result = this.evaluate(function() {
6 6 IPython.notebook.command_mode();
7 7 pos0 = IPython.notebook.get_selected_index();
8 IPython.utils.press(IPython.keyboard.keycodes.b)
8 IPython.keyboard.trigger_keydown('b');
9 9 pos1 = IPython.notebook.get_selected_index();
10 IPython.utils.press(IPython.keyboard.keycodes.b)
10 IPython.keyboard.trigger_keydown('b');
11 11 pos2 = IPython.notebook.get_selected_index();
12 12 // Simulate the "up arrow" and "down arrow" keys.
13 IPython.utils.press_up();
13 IPython.keyboard.trigger_keydown('up');
14 14 pos3 = IPython.notebook.get_selected_index();
15 IPython.utils.press_down();
15 IPython.keyboard.trigger_keydown('down');
16 16 pos4 = IPython.notebook.get_selected_index();
17 17 return pos0 == 0 &&
18 18 pos1 == 1 &&
@@ -13,8 +13,8 b' casper.notebook_test(function () {'
13 13
14 14 // Simulate the "up arrow" and "down arrow" keys.
15 15 //
16 IPython.utils.press_up();
17 IPython.utils.press_down();
16 IPython.keyboard.trigger_keydown('up');
17 IPython.keyboard.trigger_keydown('down');
18 18 return true;
19 19 });
20 20 this.test.assertTrue(result, 'Up/down arrow okay in empty notebook.');
@@ -22,7 +22,7 b' casper.notebook_test(function () {'
22 22 var cell = IPython.notebook.get_cell(0);
23 23 cell.set_text('a=11; print(a)');
24 24 cell.clear_output();
25 IPython.utils.press_shift_enter();
25 IPython.keyboard.trigger_keydown('shift+enter');
26 26 });
27 27
28 28 this.wait_for_output(0);
@@ -41,7 +41,7 b' casper.notebook_test(function () {'
41 41 var cell = IPython.notebook.get_cell(0);
42 42 cell.set_text('a=12; print(a)');
43 43 cell.clear_output();
44 IPython.utils.press_ctrl_enter();
44 IPython.keyboard.trigger_keydown('ctrl+enter');
45 45 });
46 46
47 47 this.wait_for_output(0);
@@ -32,7 +32,7 b' casper.notebook_test(function () {'
32 32
33 33 // interrupt using Ctrl-M I keyboard shortcut
34 34 this.thenEvaluate( function() {
35 IPython.utils.press_ghetto(IPython.utils.keycodes.I)
35 IPython.keyboard.trigger_keydown('i');
36 36 });
37 37
38 38 this.wait_for_output(0);
@@ -9,7 +9,7 b' casper.notebook_test(function() {'
9 9 var cell_one = IPython.notebook.get_selected_cell();
10 10 cell_one.set_text('a = 5');
11 11
12 IPython.utils.press(IPython.keyboard.keycodes.b)
12 IPython.keyboard.trigger_keydown('b');
13 13 var cell_two = IPython.notebook.get_selected_cell();
14 14 cell_two.set_text('print(a)');
15 15 };
General Comments 0
You need to be logged in to leave comments. Login now