Skip to content

Commit

Permalink
Merge pull request #4929 from ellisonbg/modal-fixes
Browse files Browse the repository at this point in the history
Fixing various modal/focus related bugs

closes #4809
closes #4951
  • Loading branch information
minrk committed Feb 1, 2014
2 parents 869d734 + f7a52c4 commit 9b8c058
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
10 changes: 9 additions & 1 deletion IPython/html/static/notebook/js/cell.js
Expand Up @@ -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);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions IPython/html/static/notebook/js/keyboardmanager.js
Expand Up @@ -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();
});
}
Expand Down
22 changes: 8 additions & 14 deletions IPython/html/static/notebook/js/widgetmanager.js
Expand Up @@ -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');
Expand All @@ -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.
Expand Down

0 comments on commit 9b8c058

Please sign in to comment.