diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js
index 38425eaf9..cbb859ab9 100644
--- a/IPython/html/static/notebook/js/keyboardmanager.js
+++ b/IPython/html/static/notebook/js/keyboardmanager.js
@@ -588,7 +588,14 @@ var IPython = (function (IPython) {
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/outputarea.js b/IPython/html/static/notebook/js/outputarea.js
index 10d12faa9..5d1d470bf 100644
--- a/IPython/html/static/notebook/js/outputarea.js
+++ b/IPython/html/static/notebook/js/outputarea.js
@@ -648,11 +648,18 @@ var IPython = (function (IPython) {
})
)
);
+
this.element.append(area);
- // weirdly need double-focus now,
- // otherwise only the cell will be focused
- area.find("input.raw_input").focus().focus();
+ var raw_input = area.find('input.raw_input');
+ // Register events that enable/disable the keyboard manager while raw
+ // input is focused.
+ IPython.keyboard_manager.register_events(raw_input);
+ // Note, the following line used to read raw_input.focus().focus().
+ // This seemed to be needed otherwise only the cell would be focused.
+ // But with the modal UI, this seems to work fine with one call to focus().
+ raw_input.focus();
}
+
OutputArea.prototype._submit_raw_input = function (evt) {
var container = this.element.find("div.raw_input");
var theprompt = container.find("span.input_prompt");