Moved edit_mode canceling logic back into cell.

This commit is contained in:
Jonathan Frederic 2014-02-27 09:50:56 -08:00
parent ff37fb7a36
commit b976804051
2 changed files with 10 additions and 47 deletions

View File

@ -142,12 +142,15 @@ var IPython = (function (IPython) {
}
if (this.code_mirror) {
this.code_mirror.on('focus', function(cm, change) {
$([IPython.events]).trigger('focus_text.Cell', {cell: that});
$([IPython.events]).trigger('edit_mode.Cell', {cell: that});
});
}
if (this.code_mirror) {
this.code_mirror.on('blur', function(cm, change) {
$([IPython.events]).trigger('blur_text.Cell', {cell: that});
// Check if this unfocus event is legit.
if (!that.should_cancel_blur()) {
$([IPython.events]).trigger('command_mode.Cell', {cell: that});
}
});
}
};
@ -267,7 +270,7 @@ var IPython = (function (IPython) {
* @return results {bool} Whether or not to ignore the cell's blur event.
**/
Cell.prototype.should_cancel_blur = function () {
return false;
return IPython.tooltip && IPython.tooltip.is_visible();
};
/**

View File

@ -115,12 +115,12 @@ var IPython = (function (IPython) {
that.select(index);
});
$([IPython.events]).on('focus_text.Cell', function (event, data) {
that.handle_cell_text_focus(data.cell);
$([IPython.events]).on('edit_mode.Cell', function (event, data) {
that.edit_mode(false, that.find_cell_index(data.cell));
});
$([IPython.events]).on('blur_text.Cell', function (event, data) {
that.handle_cell_text_blur(data.cell);
$([IPython.events]).on('command_mode.Cell', function (event, data) {
that.command_mode();
});
$([IPython.events]).on('status_autorestarting.Kernel', function () {
@ -583,46 +583,6 @@ var IPython = (function (IPython) {
cell.focus_cell();
};
/**
* Handles when the text area of a cell (codemirror) has been focused.
*
* @method handle_cell_text_focus
* @param cell {Cell}
**/
Notebook.prototype.handle_cell_text_focus = function (cell) {
this.edit_mode(false, this.find_cell_index(cell));
};
/**
* Handles when the text area of a cell (codemirror) has been blurred.
*
* @method handle_cell_text_blur
* @param cell {Cell}
**/
Notebook.prototype.handle_cell_text_blur = function (cell) {
// Check if this unfocus event is legit.
if (!this.should_cancel_blur(cell)) {
this.command_mode();
}
};
/**
* Determine whether or not the unfocus event should be aknowledged.
*
* @method should_cancel_blur
* @param cell {Cell}
*
* @return results {bool} Whether or not to ignore the cell's blur event.
**/
Notebook.prototype.should_cancel_blur = function (cell) {
// If the tooltip is visible, ignore the unfocus.
var tooltip_visible = IPython.tooltip && IPython.tooltip.is_visible();
if (tooltip_visible) { return true; }
// Check the cell's should_cancel_blur method.
return (cell.should_cancel_blur !== undefined && cell.should_cancel_blur());
};
// Cell movement
/**