Show More
@@ -566,8 +566,11 b' var IPython = (function (IPython) {' | |||||
566 | var cont = IPython.Cell.prototype.unselect.apply(this); |
|
566 | var cont = IPython.Cell.prototype.unselect.apply(this); | |
567 | if (cont) { |
|
567 | if (cont) { | |
568 | // When a code cell is usnelected, make sure that the corresponding |
|
568 | // When a code cell is usnelected, make sure that the corresponding | |
569 | // tooltip to that cell is closed. |
|
569 | // tooltip and completer to that cell is closed. | |
570 | IPython.tooltip.remove_and_cancel_tooltip(true); |
|
570 | IPython.tooltip.remove_and_cancel_tooltip(true); | |
|
571 | if (this.completer !== null) { | |||
|
572 | this.completer.close(); | |||
|
573 | } | |||
571 | } |
|
574 | } | |
572 | return cont; |
|
575 | return cont; | |
573 | }; |
|
576 | }; |
@@ -86,8 +86,7 b' var IPython = (function (IPython) {' | |||||
86 |
|
86 | |||
87 | Completer.prototype.startCompletion = function () { |
|
87 | Completer.prototype.startCompletion = function () { | |
88 | // call for a 'first' completion, that will set the editor and do some |
|
88 | // call for a 'first' completion, that will set the editor and do some | |
89 |
// special behavio |
|
89 | // special behavior like autopicking if only one completion available. | |
90 | // |
|
|||
91 | if (this.editor.somethingSelected()) return; |
|
90 | if (this.editor.somethingSelected()) return; | |
92 | this.done = false; |
|
91 | this.done = false; | |
93 | // use to get focus back on opera |
|
92 | // use to get focus back on opera | |
@@ -215,6 +214,8 b' var IPython = (function (IPython) {' | |||||
215 | } |
|
214 | } | |
216 | } |
|
215 | } | |
217 |
|
216 | |||
|
217 | if (!this.visible) { | |||
|
218 | console.log('add div'); | |||
218 | this.complete = $('<div/>').addClass('completions'); |
|
219 | this.complete = $('<div/>').addClass('completions'); | |
219 | this.complete.attr('id', 'complete'); |
|
220 | this.complete.attr('id', 'complete'); | |
220 |
|
221 | |||
@@ -222,11 +223,25 b' var IPython = (function (IPython) {' | |||||
222 | // https://code.google.com/p/chromium/issues/detail?id=4579 |
|
223 | // https://code.google.com/p/chromium/issues/detail?id=4579 | |
223 | this.sel = $('<select style="width: auto"/>') |
|
224 | this.sel = $('<select style="width: auto"/>') | |
224 | .attr('tabindex', -1) |
|
225 | .attr('tabindex', -1) | |
225 | .attr('multiple', 'true') |
|
226 | .attr('multiple', 'true'); | |
226 | .attr('size', Math.min(10, this.raw_result.length)); |
|
|||
227 | this.complete.append(this.sel); |
|
227 | this.complete.append(this.sel); | |
|
228 | this.visible = true; | |||
228 | $('body').append(this.complete); |
|
229 | $('body').append(this.complete); | |
229 |
|
230 | |||
|
231 | //build the container | |||
|
232 | var that = this; | |||
|
233 | this.sel.dblclick(function () { | |||
|
234 | that.pick(); | |||
|
235 | }); | |||
|
236 | this.editor.on('keydown', function (event) { | |||
|
237 | that.keydown(event); | |||
|
238 | }); | |||
|
239 | this.editor.on('keypress', function (event) { | |||
|
240 | that.keypress(event); | |||
|
241 | }); | |||
|
242 | } | |||
|
243 | this.sel.attr('size', Math.min(10, this.raw_result.length)); | |||
|
244 | ||||
230 | // After everything is on the page, compute the postion. |
|
245 | // After everything is on the page, compute the postion. | |
231 | // We put it above the code if it is too close to the bottom of the page. |
|
246 | // We put it above the code if it is too close to the bottom of the page. | |
232 | cur.ch = cur.ch-matched_text.length; |
|
247 | cur.ch = cur.ch-matched_text.length; | |
@@ -243,26 +258,9 b' var IPython = (function (IPython) {' | |||||
243 | this.complete.css('left', left + 'px'); |
|
258 | this.complete.css('left', left + 'px'); | |
244 | this.complete.css('top', top + 'px'); |
|
259 | this.complete.css('top', top + 'px'); | |
245 |
|
260 | |||
246 |
|
261 | // Clear and fill the list. | ||
247 | //build the container |
|
262 | this.sel.text(''); | |
248 | var that = this; |
|
|||
249 | this.sel.dblclick(function () { |
|
|||
250 | that.pick(); |
|
|||
251 | }); |
|
|||
252 | this.editor.on('keydown', function (event) { |
|
|||
253 | that.keydown(event); |
|
|||
254 | }); |
|
|||
255 | this.editor.on('keypress', function (event) { |
|
|||
256 | that.keypress(event); |
|
|||
257 | }); |
|
|||
258 |
|
||||
259 | this.build_gui_list(this.raw_result); |
|
263 | this.build_gui_list(this.raw_result); | |
260 |
|
||||
261 | this.sel.focus(); |
|
|||
262 | // Opera sometimes ignores focusing a freshly created node |
|
|||
263 | if (window.opera) setTimeout(function () { |
|
|||
264 | if (!this.done) this.sel.focus(); |
|
|||
265 | }, 100); |
|
|||
266 | return true; |
|
264 | return true; | |
267 | }; |
|
265 | }; | |
268 |
|
266 | |||
@@ -282,15 +280,13 b' var IPython = (function (IPython) {' | |||||
282 | Completer.prototype.close = function () { |
|
280 | Completer.prototype.close = function () { | |
283 | this.done = true; |
|
281 | this.done = true; | |
284 | $('#complete').remove(); |
|
282 | $('#complete').remove(); | |
|
283 | this.visible = false; | |||
285 | }; |
|
284 | }; | |
286 |
|
285 | |||
287 | Completer.prototype.pick = function () { |
|
286 | Completer.prototype.pick = function () { | |
288 | this.insert(this.raw_result[this.sel[0].selectedIndex]); |
|
287 | this.insert(this.raw_result[this.sel[0].selectedIndex]); | |
289 | this.close(); |
|
288 | this.close(); | |
290 | var that = this; |
|
289 | var that = this; | |
291 | setTimeout(function () { |
|
|||
292 | that.editor.focus(); |
|
|||
293 | }, 50); |
|
|||
294 | }; |
|
290 | }; | |
295 |
|
291 | |||
296 | Completer.prototype.keydown = function (event) { |
|
292 | Completer.prototype.keydown = function (event) { | |
@@ -306,11 +302,9 b' var IPython = (function (IPython) {' | |||||
306 | else if (code == keycodes.esc) { |
|
302 | else if (code == keycodes.esc) { | |
307 | CodeMirror.e_stop(event); |
|
303 | CodeMirror.e_stop(event); | |
308 | this.close(); |
|
304 | this.close(); | |
309 | this.editor.focus(); |
|
|||
310 |
|
305 | |||
311 | } else if (code == keycodes.backspace) { |
|
306 | } else if (code == keycodes.backspace) { | |
312 | this.close(); |
|
307 | this.close(); | |
313 | this.editor.focus(); |
|
|||
314 | } else if (code == keycodes.tab) { |
|
308 | } else if (code == keycodes.tab) { | |
315 | //all the fastforwarding operation, |
|
309 | //all the fastforwarding operation, | |
316 | //Check that shared start is not null which can append with prefixed completion |
|
310 | //Check that shared start is not null which can append with prefixed completion | |
@@ -322,7 +316,6 b' var IPython = (function (IPython) {' | |||||
322 | } |
|
316 | } | |
323 | this.close(); |
|
317 | this.close(); | |
324 | CodeMirror.e_stop(event); |
|
318 | CodeMirror.e_stop(event); | |
325 | this.editor.focus(); |
|
|||
326 | //reinvoke self |
|
319 | //reinvoke self | |
327 | setTimeout(function () { |
|
320 | setTimeout(function () { | |
328 | that.carry_on_completion(); |
|
321 | that.carry_on_completion(); | |
@@ -340,6 +333,7 b' var IPython = (function (IPython) {' | |||||
340 | // This simulates the old behavior of completion as you type, |
|
333 | // This simulates the old behavior of completion as you type, | |
341 | // before events were disconnected and CodeMirror stopped |
|
334 | // before events were disconnected and CodeMirror stopped | |
342 | // receiving events while the completer is focused. |
|
335 | // receiving events while the completer is focused. | |
|
336 | if (!this.visible) return; | |||
343 |
|
337 | |||
344 | var that = this; |
|
338 | var that = this; | |
345 | var code = event.keyCode; |
|
339 | var code = event.keyCode; | |
@@ -351,17 +345,7 b' var IPython = (function (IPython) {' | |||||
351 | code == keycodes.tab |
|
345 | code == keycodes.tab | |
352 | ) return; |
|
346 | ) return; | |
353 |
|
347 | |||
354 | var cur = this.editor.getCursor(); |
|
|||
355 | var completion = { |
|
|||
356 | str: String.fromCharCode(event.which), |
|
|||
357 | type: "introspection", |
|
|||
358 | from: cur, |
|
|||
359 | to: cur, |
|
|||
360 | }; |
|
|||
361 | this.insert(completion); |
|
|||
362 |
|
||||
363 | this.close(); |
|
348 | this.close(); | |
364 | this.editor.focus(); |
|
|||
365 | setTimeout(function () { |
|
349 | setTimeout(function () { | |
366 | that.carry_on_completion(); |
|
350 | that.carry_on_completion(); | |
367 | }, 50); |
|
351 | }, 50); |
General Comments 0
You need to be logged in to leave comments.
Login now