diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js index 4be262ca8..cfd138bd4 100644 --- a/IPython/html/static/base/js/utils.js +++ b/IPython/html/static/base/js/utils.js @@ -350,66 +350,6 @@ IPython.utils = (function (IPython) { "$1$2$3"); } - // some keycodes that seem to be platform/browser independent - var keycodes = { - BACKSPACE: 8, - TAB : 9, - ENTER : 13, - SHIFT : 16, - CTRL : 17, - CONTROL : 17, - ALT : 18, - CAPS_LOCK: 20, - ESC : 27, - SPACE : 32, - PGUP : 33, - PGDOWN : 34, - END : 35, - HOME : 36, - LEFT_ARROW: 37, - LEFTARROW: 37, - LEFT : 37, - UP_ARROW : 38, - UPARROW : 38, - UP : 38, - RIGHT_ARROW:39, - RIGHTARROW:39, - RIGHT : 39, - DOWN_ARROW: 40, - DOWNARROW: 40, - DOWN : 40, - I : 73, - M : 77, - // all three of these keys may be COMMAND on OS X: - LEFT_SUPER : 91, - RIGHT_SUPER : 92, - COMMAND : 93, - }; - - // trigger a key press event - var press = function (key) { - var key_press = $.Event('keydown', {which: key}); - $(document).trigger(key_press); - } - - var press_up = function() { press(keycodes.UP); }; - var press_down = function() { press(keycodes.DOWN); }; - - var press_ctrl_enter = function() { - $(document).trigger($.Event('keydown', {which: keycodes.ENTER, ctrlKey: true})); - }; - - var press_shift_enter = function() { - $(document).trigger($.Event('keydown', {which: keycodes.ENTER, shiftKey: true})); - }; - - // trigger the ctrl-m shortcut followed by one of our keys - var press_ghetto = function(key) { - $(document).trigger($.Event('keydown', {which: keycodes.M, ctrlKey: true})); - press(key); - }; - - var points_to_pixels = function (points) { // A reasonably good way of converting between points and pixels. var test = $('
'); @@ -431,7 +371,6 @@ IPython.utils = (function (IPython) { }; }; - var url_path_join = function () { // join a sequence of url components with '/' var url = ''; @@ -554,13 +493,6 @@ IPython.utils = (function (IPython) { regex_split : regex_split, uuid : uuid, fixConsole : fixConsole, - keycodes : keycodes, - press : press, - press_up : press_up, - press_down : press_down, - press_ctrl_enter : press_ctrl_enter, - press_shift_enter : press_shift_enter, - press_ghetto : press_ghetto, fixCarriageReturn : fixCarriageReturn, autoLinkUrls : autoLinkUrls, points_to_pixels : points_to_pixels, diff --git a/IPython/html/static/notebook/js/celltoolbarpresets/rawcell.js b/IPython/html/static/notebook/js/celltoolbarpresets/rawcell.js index 5560684c8..6f16cf31d 100644 --- a/IPython/html/static/notebook/js/celltoolbarpresets/rawcell.js +++ b/IPython/html/static/notebook/js/celltoolbarpresets/rawcell.js @@ -14,7 +14,6 @@ var CellToolbar = IPython.CellToolbar; var raw_cell_preset = []; - var utils = IPython.utils; var select_type = CellToolbar.utils.select_ui_generator([ ["None", "-"], @@ -58,7 +57,7 @@ var that = $(this); // Upon ENTER, click the OK button. that.find('input[type="text"]').keydown(function (event, ui) { - if (event.which === utils.keycodes.ENTER) { + if (event.which === IPython.keyboard.keycodes.enter) { that.find('.btn-primary').first().click(); return false; } diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index 5a0796822..3ef98ff09 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -45,7 +45,7 @@ var IPython = (function (IPython) { "use strict"; var utils = IPython.utils; - var key = IPython.utils.keycodes; + var keycodes = IPython.keyboard.keycodes; /** * A Cell conceived to write code. @@ -195,16 +195,16 @@ var IPython = (function (IPython) { // whatever key is pressed, first, cancel the tooltip request before // they are sent, and remove tooltip if any, except for tab again var tooltip_closed = null; - if (event.type === 'keydown' && event.which != key.TAB ) { + if (event.type === 'keydown' && event.which != keycodes.tab ) { tooltip_closed = IPython.tooltip.remove_and_cancel_tooltip(); } var cur = editor.getCursor(); - if (event.keyCode === key.ENTER){ + if (event.keyCode === keycodes.enter){ this.auto_highlight(); } - if (event.keyCode === key.ENTER && (event.shiftKey || event.ctrlKey || event.altKey)) { + if (event.keyCode === keycodes.enter && (event.shiftKey || event.ctrlKey || event.altKey)) { // Always ignore shift-enter in CodeMirror as we handle it. return true; } else if (event.which === 40 && event.type === 'keypress' && IPython.tooltip.time_before_tooltip >= 0) { @@ -214,7 +214,7 @@ var IPython = (function (IPython) { // The second argument says to hide the tooltip if the docstring // is actually empty IPython.tooltip.pending(that, true); - } else if (event.which === key.UPARROW && event.type === 'keydown') { + } else if (event.which === keycodes.up && event.type === 'keydown') { // If we are not at the top, let CM handle the up arrow and // prevent the global keydown handler from handling it. if (!that.at_top()) { @@ -223,7 +223,7 @@ var IPython = (function (IPython) { } else { return true; } - } else if (event.which === key.ESC && event.type === 'keydown') { + } else if (event.which === keycodes.esc && event.type === 'keydown') { // First see if the tooltip is active and if so cancel it. if (tooltip_closed) { // The call to remove_and_cancel_tooltip above in L177 doesn't pass @@ -249,7 +249,7 @@ var IPython = (function (IPython) { // Don't let CM handle the event, defer to global handling. return true; } - } else if (event.which === key.DOWNARROW && event.type === 'keydown') { + } else if (event.which === keycodes.down && event.type === 'keydown') { // If we are not at the bottom, let CM handle the down arrow and // prevent the global keydown handler from handling it. if (!that.at_bottom()) { @@ -258,7 +258,7 @@ var IPython = (function (IPython) { } else { return true; } - } else if (event.keyCode === key.TAB && event.type === 'keydown' && event.shiftKey) { + } else if (event.keyCode === keycodes.tab && event.type === 'keydown' && event.shiftKey) { if (editor.somethingSelected()){ var anchor = editor.getCursor("anchor"); var head = editor.getCursor("head"); @@ -269,7 +269,7 @@ var IPython = (function (IPython) { IPython.tooltip.request(that); event.stop(); return true; - } else if (event.keyCode === key.TAB && event.type == 'keydown') { + } else if (event.keyCode === keycodes.tab && event.type == 'keydown') { // Tab completion. IPython.tooltip.remove_and_cancel_tooltip(); if (editor.somethingSelected()) { diff --git a/IPython/html/static/notebook/js/completer.js b/IPython/html/static/notebook/js/completer.js index 5b8c5186d..b86cd0c31 100644 --- a/IPython/html/static/notebook/js/completer.js +++ b/IPython/html/static/notebook/js/completer.js @@ -6,7 +6,7 @@ var IPython = (function (IPython) { "use strict"; // easier key mapping - var key = IPython.utils.keycodes; + var keycodes = IPython.keyboard.keycodes; function prepend_n_prc(str, n) { for( var i =0 ; i< n ; i++){ @@ -317,19 +317,20 @@ var IPython = (function (IPython) { } // Enter - if (code == key.ENTER) { + if (code == keycodes.enter) { CodeMirror.e_stop(event); this.pick(); } // Escape or backspace - else if (code == key.ESC) { + else if (code == keycodes.esc) { CodeMirror.e_stop(event); this.close(); this.editor.focus(); - } else if (code == key.BACKSPACE) { + + } else if (code == keycodes.backspace) { this.close(); this.editor.focus(); - } else if (code == key.TAB) { + } else if (code == keycodes.tab) { //all the fastforwarding operation, //Check that shared start is not null which can append with prefixed completion // like %pylab , pylab have no shred start, and ff will result in py @@ -345,7 +346,7 @@ var IPython = (function (IPython) { setTimeout(function () { that.carry_on_completion(); }, 50); - } else if (code == key.UPARROW || code == key.DOWNARROW) { + } else if (code == keycodes.up || code == keycodes.down) { // need to do that to be able to move the arrow // when on the first or last line ofo a code cell event.stopPropagation(); diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 97b2edb89..d49fd4984 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1917,7 +1917,7 @@ var IPython = (function (IPython) { var that = $(this); // Upon ENTER, click the OK button. that.find('input[type="text"]').keydown(function (event, ui) { - if (event.which === utils.keycodes.ENTER) { + if (event.which === IPython.keyboard.keycodes.enter) { that.find('.btn-primary').first().click(); } }); diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index c67e2b332..d4e14565e 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -669,7 +669,7 @@ var IPython = (function (IPython) { .keydown(function (event, ui) { // make sure we submit on enter, // and don't re-execute the *cell* on shift-enter - if (event.which === utils.keycodes.ENTER) { + if (event.which === IPython.keyboard.keycodes.enter) { that._submit_raw_input(); return false; } diff --git a/IPython/html/static/notebook/js/savewidget.js b/IPython/html/static/notebook/js/savewidget.js index 046e35d73..f6455717b 100644 --- a/IPython/html/static/notebook/js/savewidget.js +++ b/IPython/html/static/notebook/js/savewidget.js @@ -103,7 +103,7 @@ var IPython = (function (IPython) { var that = $(this); // Upon ENTER, click the OK button. that.find('input[type="text"]').keydown(function (event, ui) { - if (event.which === utils.keycodes.ENTER) { + if (event.which === IPython.keyboard.keycodes.enter) { that.find('.btn-primary').first().click(); return false; } diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index 4db5e8ab3..65d8e3a44 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -20,7 +20,7 @@ var IPython = (function (IPython) { "use strict"; // TextCell base class - var key = IPython.utils.keycodes; + var keycodes = IPython.keyboard.keycodes; /** * Construct a new TextCell, codemirror mode is by default 'htmlmixed', and cell type is 'text' @@ -140,7 +140,7 @@ var IPython = (function (IPython) { if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey || event.altKey)) { // Always ignore shift-enter in CodeMirror as we handle it. return true; - } else if (event.which === key.UPARROW && event.type === 'keydown') { + } else if (event.which === keycodes.up && event.type === 'keydown') { // If we are not at the top, let CM handle the up arrow and // prevent the global keydown handler from handling it. if (!that.at_top()) { @@ -148,8 +148,8 @@ var IPython = (function (IPython) { return false; } else { return true; - } - } else if (event.which === key.DOWNARROW && event.type === 'keydown') { + }; + } else if (event.which === keycodes.down && event.type === 'keydown') { // If we are not at the bottom, let CM handle the down arrow and // prevent the global keydown handler from handling it. if (!that.at_bottom()) { @@ -157,8 +157,8 @@ var IPython = (function (IPython) { return false; } else { return true; - } - } else if (event.which === key.ESC && event.type === 'keydown') { + }; + } else if (event.which === keycodes.esc && event.type === 'keydown') { if (that.code_mirror.options.keyMap === "vim-insert") { // vim keyMap is active and in insert mode. In this case we leave vim // insert mode, but remain in notebook edit mode. diff --git a/IPython/html/tests/notebook/empty_arrow_keys.js b/IPython/html/tests/notebook/empty_arrow_keys.js index ca26557f3..6abed3a96 100644 --- a/IPython/html/tests/notebook/empty_arrow_keys.js +++ b/IPython/html/tests/notebook/empty_arrow_keys.js @@ -13,8 +13,8 @@ casper.notebook_test(function () { // Simulate the "up arrow" and "down arrow" keys. // - IPython.utils.press_up(); - IPython.utils.press_down(); + IPython.keyboard.trigger_keydown('up'); + IPython.keyboard.trigger_keydown('down'); return true; }); this.test.assertTrue(result, 'Up/down arrow okay in empty notebook.'); diff --git a/IPython/html/tests/notebook/execute_code.js b/IPython/html/tests/notebook/execute_code.js index 14db3577f..fc399e47b 100644 --- a/IPython/html/tests/notebook/execute_code.js +++ b/IPython/html/tests/notebook/execute_code.js @@ -22,7 +22,7 @@ casper.notebook_test(function () { var cell = IPython.notebook.get_cell(0); cell.set_text('a=11; print(a)'); cell.clear_output(); - IPython.utils.press_shift_enter(); + IPython.keyboard.trigger_keydown('shift+enter'); }); this.wait_for_output(0); @@ -41,7 +41,7 @@ casper.notebook_test(function () { var cell = IPython.notebook.get_cell(0); cell.set_text('a=12; print(a)'); cell.clear_output(); - IPython.utils.press_ctrl_enter(); + IPython.keyboard.trigger_keydown('ctrl+enter'); }); this.wait_for_output(0); diff --git a/IPython/html/tests/notebook/interrupt.js b/IPython/html/tests/notebook/interrupt.js index 5e4b07c6e..2bb87f8a5 100644 --- a/IPython/html/tests/notebook/interrupt.js +++ b/IPython/html/tests/notebook/interrupt.js @@ -32,7 +32,7 @@ casper.notebook_test(function () { // interrupt using Ctrl-M I keyboard shortcut this.thenEvaluate( function() { - IPython.utils.press_ghetto(IPython.utils.keycodes.I) + IPython.keyboard.trigger_keydown('i'); }); this.wait_for_output(0); diff --git a/IPython/html/tests/notebook/merge_cells.js b/IPython/html/tests/notebook/merge_cells.js index a7a681c9d..2d8561433 100644 --- a/IPython/html/tests/notebook/merge_cells.js +++ b/IPython/html/tests/notebook/merge_cells.js @@ -9,7 +9,7 @@ casper.notebook_test(function() { var cell_one = IPython.notebook.get_selected_cell(); cell_one.set_text('a = 5'); - IPython.utils.press(IPython.keyboard.keycodes.b) + IPython.keyboard.trigger_keydown('b'); var cell_two = IPython.notebook.get_selected_cell(); cell_two.set_text('print(a)'); };