Show More
@@ -455,6 +455,26 IPython.utils = (function (IPython) { | |||||
455 | return M; |
|
455 | return M; | |
456 | })(); |
|
456 | })(); | |
457 |
|
457 | |||
|
458 | var is_or_has = function (a, b) { | |||
|
459 | // Is b a child of a or a itself? | |||
|
460 | return a.has(b).length !==0 || a.is(b); | |||
|
461 | } | |||
|
462 | ||||
|
463 | var is_focused = function (e) { | |||
|
464 | // Is element e, or one of its children focused? | |||
|
465 | e = $(e); | |||
|
466 | var target = $(document.activeElement); | |||
|
467 | if (target.length > 0) { | |||
|
468 | if (is_or_has(e, target)) { | |||
|
469 | return true; | |||
|
470 | } else { | |||
|
471 | return false; | |||
|
472 | } | |||
|
473 | } else { | |||
|
474 | return false; | |||
|
475 | } | |||
|
476 | } | |||
|
477 | ||||
458 |
|
478 | |||
459 | return { |
|
479 | return { | |
460 | regex_split : regex_split, |
|
480 | regex_split : regex_split, | |
@@ -475,7 +495,9 IPython.utils = (function (IPython) { | |||||
475 | encode_uri_components : encode_uri_components, |
|
495 | encode_uri_components : encode_uri_components, | |
476 | splitext : splitext, |
|
496 | splitext : splitext, | |
477 | always_new : always_new, |
|
497 | always_new : always_new, | |
478 | browser : browser |
|
498 | browser : browser, | |
|
499 | is_or_has : is_or_has, | |||
|
500 | is_focused : is_focused | |||
479 | }; |
|
501 | }; | |
480 |
|
502 | |||
481 | }(IPython)); |
|
503 | }(IPython)); |
@@ -110,52 +110,15 var IPython = (function (IPython) { | |||||
110 | var that = this; |
|
110 | var that = this; | |
111 | // We trigger events so that Cell doesn't have to depend on Notebook. |
|
111 | // We trigger events so that Cell doesn't have to depend on Notebook. | |
112 | that.element.click(function (event) { |
|
112 | that.element.click(function (event) { | |
113 |
if (that.selected |
|
113 | if (!that.selected) { | |
114 | $([IPython.events]).trigger('select.Cell', {'cell':that}); |
|
114 | $([IPython.events]).trigger('select.Cell', {'cell':that}); | |
115 | }; |
|
115 | }; | |
116 | }); |
|
116 | }); | |
117 | that.element.focusin(function (event) { |
|
117 | that.element.focusin(function (event) { | |
118 |
if (that.selected |
|
118 | if (!that.selected) { | |
119 | $([IPython.events]).trigger('select.Cell', {'cell':that}); |
|
119 | $([IPython.events]).trigger('select.Cell', {'cell':that}); | |
120 | }; |
|
120 | }; | |
121 | }); |
|
121 | }); | |
122 | that.element.focusout(function (event) { |
|
|||
123 | var is_or_has = function (a, b) { |
|
|||
124 | // Is b a child of a or a itself? |
|
|||
125 | return a.has(b).length !==0 || a.is(b); |
|
|||
126 | } |
|
|||
127 | if (that.mode === 'edit') { |
|
|||
128 | // Most of the time, when a cell is in edit mode and focusout |
|
|||
129 | // fires, it means we should enter command mode. But there are cases |
|
|||
130 | // when we should not enter command mode. |
|
|||
131 | setTimeout(function () { |
|
|||
132 | var trigger = true; |
|
|||
133 | var target = $(document.activeElement); |
|
|||
134 | var completer = $('div.completions'); |
|
|||
135 | var tooltip = $('div#tooltip'); |
|
|||
136 | if (target.length > 0) { |
|
|||
137 | // If the focused element (target) is inside the cell |
|
|||
138 | // (that.element) don't enter command mode. |
|
|||
139 | if (is_or_has(that.element, target)) { |
|
|||
140 | trigger = false; |
|
|||
141 | // The focused element is outside the cell |
|
|||
142 | } else { |
|
|||
143 | // If the focused element is the tooltip or completer |
|
|||
144 | // don't enter command mode, otherwise do. |
|
|||
145 | trigger = true; |
|
|||
146 | if (tooltip.length > 0 && is_or_has(tooltip, target)) { |
|
|||
147 | trigger = false; |
|
|||
148 | } else if (completer.length > 0 && is_or_has(completer, target)) { |
|
|||
149 | trigger = false; |
|
|||
150 | } |
|
|||
151 | } |
|
|||
152 | } |
|
|||
153 | if (trigger) { |
|
|||
154 | $([IPython.events]).trigger('command_mode.Cell', {'cell':that}); |
|
|||
155 | } |
|
|||
156 | }, 1); |
|
|||
157 | }; |
|
|||
158 | }); |
|
|||
159 | if (this.code_mirror) { |
|
122 | if (this.code_mirror) { | |
160 | this.code_mirror.on("change", function(cm, change) { |
|
123 | this.code_mirror.on("change", function(cm, change) { | |
161 | $([IPython.events]).trigger("set_dirty.Notebook", {value: true}); |
|
124 | $([IPython.events]).trigger("set_dirty.Notebook", {value: true}); | |
@@ -166,6 +129,22 var IPython = (function (IPython) { | |||||
166 | $([IPython.events]).trigger('edit_mode.Cell', {cell: that}); |
|
129 | $([IPython.events]).trigger('edit_mode.Cell', {cell: that}); | |
167 | }); |
|
130 | }); | |
168 | }; |
|
131 | }; | |
|
132 | if (this.code_mirror) { | |||
|
133 | this.code_mirror.on('blur', function(cm, change) { | |||
|
134 | if (that.mode === 'edit') { | |||
|
135 | setTimeout(function () { | |||
|
136 | var isf = IPython.utils.is_focused; | |||
|
137 | var trigger = true; | |||
|
138 | if (isf('div#tooltip') || isf('div.completions')) { | |||
|
139 | trigger = false; | |||
|
140 | } | |||
|
141 | if (trigger) { | |||
|
142 | $([IPython.events]).trigger('command_mode.Cell', {cell: that}); | |||
|
143 | } | |||
|
144 | }, 1); | |||
|
145 | } | |||
|
146 | }); | |||
|
147 | }; | |||
169 | }; |
|
148 | }; | |
170 |
|
149 | |||
171 | /** |
|
150 | /** |
General Comments 0
You need to be logged in to leave comments.
Login now