##// END OF EJS Templates
Moved edit_mode canceling logic back into cell.
Jonathan Frederic -
Show More
@@ -142,12 +142,15 b' var IPython = (function (IPython) {'
142 }
142 }
143 if (this.code_mirror) {
143 if (this.code_mirror) {
144 this.code_mirror.on('focus', function(cm, change) {
144 this.code_mirror.on('focus', function(cm, change) {
145 $([IPython.events]).trigger('focus_text.Cell', {cell: that});
145 $([IPython.events]).trigger('edit_mode.Cell', {cell: that});
146 });
146 });
147 }
147 }
148 if (this.code_mirror) {
148 if (this.code_mirror) {
149 this.code_mirror.on('blur', function(cm, change) {
149 this.code_mirror.on('blur', function(cm, change) {
150 $([IPython.events]).trigger('blur_text.Cell', {cell: that});
150 // Check if this unfocus event is legit.
151 if (!that.should_cancel_blur()) {
152 $([IPython.events]).trigger('command_mode.Cell', {cell: that});
153 }
151 });
154 });
152 }
155 }
153 };
156 };
@@ -267,7 +270,7 b' var IPython = (function (IPython) {'
267 * @return results {bool} Whether or not to ignore the cell's blur event.
270 * @return results {bool} Whether or not to ignore the cell's blur event.
268 **/
271 **/
269 Cell.prototype.should_cancel_blur = function () {
272 Cell.prototype.should_cancel_blur = function () {
270 return false;
273 return IPython.tooltip && IPython.tooltip.is_visible();
271 };
274 };
272
275
273 /**
276 /**
@@ -115,12 +115,12 b' var IPython = (function (IPython) {'
115 that.select(index);
115 that.select(index);
116 });
116 });
117
117
118 $([IPython.events]).on('focus_text.Cell', function (event, data) {
118 $([IPython.events]).on('edit_mode.Cell', function (event, data) {
119 that.handle_cell_text_focus(data.cell);
119 that.edit_mode(false, that.find_cell_index(data.cell));
120 });
120 });
121
121
122 $([IPython.events]).on('blur_text.Cell', function (event, data) {
122 $([IPython.events]).on('command_mode.Cell', function (event, data) {
123 that.handle_cell_text_blur(data.cell);
123 that.command_mode();
124 });
124 });
125
125
126 $([IPython.events]).on('status_autorestarting.Kernel', function () {
126 $([IPython.events]).on('status_autorestarting.Kernel', function () {
@@ -583,46 +583,6 b' var IPython = (function (IPython) {'
583 cell.focus_cell();
583 cell.focus_cell();
584 };
584 };
585
585
586 /**
587 * Handles when the text area of a cell (codemirror) has been focused.
588 *
589 * @method handle_cell_text_focus
590 * @param cell {Cell}
591 **/
592 Notebook.prototype.handle_cell_text_focus = function (cell) {
593 this.edit_mode(false, this.find_cell_index(cell));
594 };
595
596 /**
597 * Handles when the text area of a cell (codemirror) has been blurred.
598 *
599 * @method handle_cell_text_blur
600 * @param cell {Cell}
601 **/
602 Notebook.prototype.handle_cell_text_blur = function (cell) {
603 // Check if this unfocus event is legit.
604 if (!this.should_cancel_blur(cell)) {
605 this.command_mode();
606 }
607 };
608
609 /**
610 * Determine whether or not the unfocus event should be aknowledged.
611 *
612 * @method should_cancel_blur
613 * @param cell {Cell}
614 *
615 * @return results {bool} Whether or not to ignore the cell's blur event.
616 **/
617 Notebook.prototype.should_cancel_blur = function (cell) {
618 // If the tooltip is visible, ignore the unfocus.
619 var tooltip_visible = IPython.tooltip && IPython.tooltip.is_visible();
620 if (tooltip_visible) { return true; }
621
622 // Check the cell's should_cancel_blur method.
623 return (cell.should_cancel_blur !== undefined && cell.should_cancel_blur());
624 };
625
626 // Cell movement
586 // Cell movement
627
587
628 /**
588 /**
General Comments 0
You need to be logged in to leave comments. Login now