From 9b8c058d4ef1667b292fea5e5a365aa545da6112 2014-02-01 04:40:25 From: Min RK Date: 2014-02-01 04:40:25 Subject: [PATCH] Merge pull request #4929 from ellisonbg/modal-fixes Fixing various modal/focus related bugs closes #4809 closes #4951 --- diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index c14a125..decd947 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -288,8 +288,16 @@ var IPython = (function (IPython) { * @method focus_editor */ Cell.prototype.focus_editor = function () { + var that = this; this.refresh(); - this.code_mirror.focus(); + // Only focus the CM editor if it is not focused already. This prevents jumps + // related to the previous prompt position. + setTimeout(function () { + var isf = IPython.utils.is_focused; + if (!isf(that.element.find('div.CodeMirror'))) { + that.code_mirror.focus(); + } + }, 1); } /** diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index 5a8c3bc..1e10142 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -740,18 +740,15 @@ var IPython = (function (IPython) { KeyboardManager.prototype.register_events = function (e) { var that = this; e.on('focusin', function () { - that.command_mode(); that.disable(); }); e.on('focusout', function () { - that.command_mode(); that.enable(); }); // There are times (raw_input) where we remove the element from the DOM before // focusout is called. In this case we bind to the remove event of jQueryUI, // which gets triggered upon removal. e.on('remove', function () { - that.command_mode(); that.enable(); }); } diff --git a/IPython/html/static/notebook/js/widgetmanager.js b/IPython/html/static/notebook/js/widgetmanager.js index 5dbdd35..afd8f3f 100644 --- a/IPython/html/static/notebook/js/widgetmanager.js +++ b/IPython/html/static/notebook/js/widgetmanager.js @@ -83,13 +83,20 @@ console.error("View creation failed", model); } if (cell.widget_subarea) { - cell.widget_area.show(); + this._handle_display_view(view); cell.widget_subarea.append(view.$el); } } }; + WidgetManager.prototype._handle_display_view = function (view) { + // Have the IPython keyboard manager disable its event + // handling so the widget can capture keyboard input. + // Note, this is only done on the outer most widget. + IPython.keyboard_manager.register_events(view.$el); + }; + WidgetManager.prototype.create_view = function(model, options, view) { // Creates a view for a particular model. var view_name = model.get('_view_name'); @@ -109,24 +116,11 @@ view.render(); model.views.push(view); model.on('destroy', view.remove, view); - - this._handle_new_view(view); return view; } return null; }; - WidgetManager.prototype._handle_new_view = function (view) { - // Called when a view has been created and rendered. - - // If the view has a well defined element, inform the keyboard - // manager about the view's element, so as the element can - // escape the dreaded command mode. - if (view.$el) { - IPython.keyboard_manager.register_events(view.$el); - } - }; - WidgetManager.prototype.get_msg_cell = function (msg_id) { var cell = null; // First, check to see if the msg was triggered by cell execution.