From ba2ee9adc3ccbdd2e20f846086fce2e4480e160f 2014-10-10 17:18:56 From: Matthias Bussonnier Date: 2014-10-10 17:18:56 Subject: [PATCH] rework keyboard management to avoit completer and up/down bugs --- diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index 4533d14..1929d86 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -198,9 +198,22 @@ define([ Cell.prototype.handle_codemirror_keyevent = function (editor, event) { var shortcuts = this.keyboard_manager.edit_shortcuts; + var cur = editor.getCursor(); + if((cur.line !== 0 || cur.ch !==0) && event.keyCode === 38){ + event._ipkmIgnore = true; + } + var nLastLine = editor.lastLine() + if( ( event.keyCode === 40) + && (( cur.line !== nLastLine) + || ( cur.ch !== editor.getLineHandle(nLastLine).text.length)) + ){ + event._ipkmIgnore = true; + } // if this is an edit_shortcuts shortcut, the global keyboard/shortcut // manager will handle it - if (shortcuts.handles(event)) { return true; } + if (shortcuts.handles(event)) { + return true; + } return false; }; @@ -291,7 +304,6 @@ define([ * @return {Boolean} `true` if CodeMirror should ignore the event, `false` Otherwise */ Cell.prototype.handle_keyevent = function (editor, event) { - if (this.mode === 'command') { return true; } else if (this.mode === 'edit') { diff --git a/IPython/html/static/notebook/js/celltoolbar.js b/IPython/html/static/notebook/js/celltoolbar.js index 887eba3..1d5e259 100644 --- a/IPython/html/static/notebook/js/celltoolbar.js +++ b/IPython/html/static/notebook/js/celltoolbar.js @@ -114,7 +114,7 @@ define([ * @param name {String} name to use to refer to the callback. It is advised to use a prefix with the name * for easier sorting and avoid collision * @param callback {function(div, cell)} callback that will be called to generate the ui element - * @param [cell_types] {List of String|undefined} optional list of cell types. If present the UI element + * @param [cell_types] {List_of_String|undefined} optional list of cell types. If present the UI element * will be added only to cells of types in the list. * * @@ -163,7 +163,7 @@ define([ * @method register_preset * @param name {String} name to use to refer to the preset. It is advised to use a prefix with the name * for easier sorting and avoid collision - * @param preset_list {List of String} reverse order of the button in the toolbar. Each String of the list + * @param preset_list {List_of_String} reverse order of the button in the toolbar. Each String of the list * should correspond to a name of a registerd callback. * * @private @@ -288,8 +288,6 @@ define([ }; - /** - */ CellToolbar.utils = {}; @@ -385,7 +383,7 @@ define([ * @method utils.select_ui_generator * @static * - * @param list_list {list of sublist} List of sublist of metadata value and name in the dropdown list. + * @param list_list {list_of_sublist} List of sublist of metadata value and name in the dropdown list. * subslit shoud contain 2 element each, first a string that woul be displayed in the dropdown list, * and second the corresponding value to be passed to setter/return by getter. the corresponding value * should not be "undefined" or behavior can be unexpected. diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index d23d56c..05f688a 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -83,11 +83,7 @@ define([ this.completer = null; - var cm_overwrite_options = { - onKeyEvent: $.proxy(this.handle_keyevent,this) - }; - - var config = utils.mergeopt(CodeCell, this.config, {cm_config: cm_overwrite_options}); + var config = utils.mergeopt(CodeCell, this.config); Cell.apply(this,[{ config: config, keyboard_manager: options.keyboard_manager, @@ -144,7 +140,7 @@ define([ inner_cell.append(this.celltoolbar.element); var input_area = $('
').addClass('input_area'); this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config); - this.code_mirror.on('keydown', $.proxy(this.handle_codemirror_keyevent,this)) + this.code_mirror.on('keydown', $.proxy(this.handle_keyevent,this)) $(this.code_mirror.getInputField()).attr("spellcheck", "false"); inner_cell.append(input_area); input.append(prompt).append(inner_cell); diff --git a/IPython/html/static/notebook/js/completer.js b/IPython/html/static/notebook/js/completer.js index 576885c..97fc0cf 100644 --- a/IPython/html/static/notebook/js/completer.js +++ b/IPython/html/static/notebook/js/completer.js @@ -318,11 +318,13 @@ define([ // Enter if (code == keycodes.enter) { event.codemirrorIgnore = true; + event._ipkmIgnore = true; event.preventDefault(); this.pick(); // Escape or backspace } else if (code == keycodes.esc || code == keycodes.backspace) { event.codemirrorIgnore = true; + event._ipkmIgnore = true; event.preventDefault(); this.close(); } else if (code == keycodes.tab) { @@ -343,6 +345,7 @@ define([ // need to do that to be able to move the arrow // when on the first or last line ofo a code cell event.codemirrorIgnore = true; + event._ipkmIgnore = true; event.preventDefault(); var options = this.sel.find('option'); @@ -356,7 +359,7 @@ define([ index = Math.min(Math.max(index, 0), options.length-1); this.sel[0].selectedIndex = index; } else if (code == keycodes.pageup || code == keycodes.pagedown) { - CodeMirror.e_stop(event); + event._ipkmIgnore = true; var options = this.sel.find('option'); var index = this.sel[0].selectedIndex; diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index c315b4e..e83ed95 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -227,6 +227,9 @@ define([ help : 'select previous cell', help_index : 'da', handler : function (event) { + if(event.codemirrorIgnore===true){ + return false; + } var index = that.notebook.get_selected_index(); if (index !== 0 && index !== null) { that.notebook.select_prev(); @@ -239,6 +242,9 @@ define([ help : 'select next cell', help_index : 'db', handler : function (event) { + if(event.codemirrorIgnore===true){ + return false; + } var index = that.notebook.get_selected_index(); if (index !== (that.notebook.ncells()-1) && index !== null) { that.notebook.select_next(); @@ -508,6 +514,9 @@ define([ KeyboardManager.prototype.bind_events = function () { var that = this; $(document).keydown(function (event) { + if(event._ipkmIgnore==true||event.originalEvent._ipkmIgnore==true){ + return false; + } return that.handle_keydown(event); }); }; diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 3467ffc..a2839c8 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -893,7 +893,7 @@ define([ * Insert an element at given cell index. * * @method _insert_element_at_index - * @param element {dom element} a cell element + * @param element {dom_element} a cell element * @param [index] {int} a valid index where to inser cell * @private * diff --git a/IPython/html/static/notebook/js/toolbar.js b/IPython/html/static/notebook/js/toolbar.js index 5f6c192..4040659 100644 --- a/IPython/html/static/notebook/js/toolbar.js +++ b/IPython/html/static/notebook/js/toolbar.js @@ -11,7 +11,7 @@ define([ * A generic toolbar on which one can add button * @class ToolBar * @constructor - * @param {Dom object} selector + * @param {Dom_object} selector */ var ToolBar = function (selector, layout_manager) { this.selector = selector;