Show More
@@ -233,10 +233,17 var IPython = (function (IPython) { | |||||
233 | this.sel.dblclick(function () { |
|
233 | this.sel.dblclick(function () { | |
234 | that.pick(); |
|
234 | that.pick(); | |
235 | }); |
|
235 | }); | |
|
236 | this.sel.focus(function () { | |||
|
237 | that.editor.focus(); | |||
|
238 | }); | |||
236 | this._handle_keydown = function (cm, event) { |
|
239 | this._handle_keydown = function (cm, event) { | |
237 | that.keydown(event); |
|
240 | that.keydown(event); | |
238 | }; |
|
241 | }; | |
239 | this.editor.on('keydown', this._handle_keydown); |
|
242 | this.editor.on('keydown', this._handle_keydown); | |
|
243 | this._handle_keypress = function (cm, event) { | |||
|
244 | that.keypress(event); | |||
|
245 | }; | |||
|
246 | this.editor.on('keypress', this._handle_keypress); | |||
240 | } |
|
247 | } | |
241 | this.sel.attr('size', Math.min(10, this.raw_result.length)); |
|
248 | this.sel.attr('size', Math.min(10, this.raw_result.length)); | |
242 |
|
249 | |||
@@ -282,6 +289,10 var IPython = (function (IPython) { | |||||
282 | this.editor.off('keydown', this._handle_keydown); |
|
289 | this.editor.off('keydown', this._handle_keydown); | |
283 | this._handle_keydown = undefined; |
|
290 | this._handle_keydown = undefined; | |
284 | } |
|
291 | } | |
|
292 | if (this._handle_keypress) { | |||
|
293 | this.editor.off('keypress', this._handle_keypress); | |||
|
294 | this._handle_keypress = undefined; | |||
|
295 | } | |||
285 | this.visible = false; |
|
296 | this.visible = false; | |
286 | }; |
|
297 | }; | |
287 |
|
298 | |||
@@ -291,20 +302,16 var IPython = (function (IPython) { | |||||
291 | }; |
|
302 | }; | |
292 |
|
303 | |||
293 | Completer.prototype.keydown = function (event) { |
|
304 | Completer.prototype.keydown = function (event) { | |
294 | console.log(event); |
|
|||
295 | var code = event.keyCode; |
|
305 | var code = event.keyCode; | |
296 | var that = this; |
|
306 | var that = this; | |
297 | if (!this.visible) return; |
|
|||
298 |
|
307 | |||
299 | // Enter |
|
308 | // Enter | |
300 | if (code == keycodes.enter) { |
|
309 | if (code == keycodes.enter) { | |
301 | event.stopPropagation(); |
|
310 | CodeMirror.e_stop(event); | |
302 | event.codemirrorIgnore = true; |
|
|||
303 | this.pick(); |
|
311 | this.pick(); | |
304 | // Escape or backspace |
|
312 | // Escape or backspace | |
305 | } else if (code == keycodes.esc || code == keycodes.backspace) { |
|
313 | } else if (code == keycodes.esc || code == keycodes.backspace) { | |
306 | event.stopPropagation(); |
|
314 | CodeMirror.e_stop(event); | |
307 | event.codemirrorIgnore = true; |
|
|||
308 | this.close(); |
|
315 | this.close(); | |
309 | } else if (code == keycodes.tab) { |
|
316 | } else if (code == keycodes.tab) { | |
310 | //all the fastforwarding operation, |
|
317 | //all the fastforwarding operation, | |
@@ -316,8 +323,8 var IPython = (function (IPython) { | |||||
316 | this.insert(sh); |
|
323 | this.insert(sh); | |
317 | } |
|
324 | } | |
318 | this.close(); |
|
325 | this.close(); | |
319 | event.codemirrorIgnore = true; |
|
326 | // event.codemirrorIgnore = true; | |
320 | event.stopPropagation(); |
|
327 | // event.stopPropagation(); | |
321 | //reinvoke self |
|
328 | //reinvoke self | |
322 | setTimeout(function () { |
|
329 | setTimeout(function () { | |
323 | that.carry_on_completion(); |
|
330 | that.carry_on_completion(); | |
@@ -325,8 +332,7 var IPython = (function (IPython) { | |||||
325 | } else if (code == keycodes.up || code == keycodes.down) { |
|
332 | } else if (code == keycodes.up || code == keycodes.down) { | |
326 | // need to do that to be able to move the arrow |
|
333 | // need to do that to be able to move the arrow | |
327 | // when on the first or last line ofo a code cell |
|
334 | // when on the first or last line ofo a code cell | |
328 | event.stopPropagation(); |
|
335 | CodeMirror.e_stop(event); | |
329 | event.codemirrorIgnore = true; |
|
|||
330 |
|
336 | |||
331 | var options = this.sel.find('option'); |
|
337 | var options = this.sel.find('option'); | |
332 | var index = this.sel[0].selectedIndex; |
|
338 | var index = this.sel[0].selectedIndex; | |
@@ -337,11 +343,44 var IPython = (function (IPython) { | |||||
337 | index++; |
|
343 | index++; | |
338 | } |
|
344 | } | |
339 | index = Math.min(Math.max(index, 0), options.length-1); |
|
345 | index = Math.min(Math.max(index, 0), options.length-1); | |
340 | console.log('compl set index', index); |
|
|||
341 | this.sel[0].selectedIndex = index; |
|
346 | this.sel[0].selectedIndex = index; | |
|
347 | } else if (code == keycodes.left || code == keycodes.right) { | |||
|
348 | this.close(); | |||
342 | } |
|
349 | } | |
343 | }; |
|
350 | }; | |
344 |
|
351 | |||
|
352 | Completer.prototype.keypress = function (event) { | |||
|
353 | // FIXME: This is a band-aid. | |||
|
354 | // on keypress, trigger insertion of a single character. | |||
|
355 | // This simulates the old behavior of completion as you type, | |||
|
356 | // before events were disconnected and CodeMirror stopped | |||
|
357 | // receiving events while the completer is focused. | |||
|
358 | ||||
|
359 | var that = this; | |||
|
360 | var code = event.keyCode; | |||
|
361 | ||||
|
362 | // don't handle keypress if it's not a character (arrows on FF) | |||
|
363 | // or ENTER/TAB | |||
|
364 | if (event.charCode === 0 || | |||
|
365 | code == keycodes.tab || | |||
|
366 | code == keycodes.enter | |||
|
367 | ) return; | |||
|
368 | ||||
|
369 | var cur = this.editor.getCursor(); | |||
|
370 | var completion = { | |||
|
371 | str: String.fromCharCode(event.which), | |||
|
372 | type: "introspection", | |||
|
373 | from: cur, | |||
|
374 | to: cur, | |||
|
375 | }; | |||
|
376 | // this.insert(completion); | |||
|
377 | ||||
|
378 | this.close(); | |||
|
379 | this.editor.focus(); | |||
|
380 | setTimeout(function () { | |||
|
381 | that.carry_on_completion(); | |||
|
382 | }, 50); | |||
|
383 | }; | |||
345 | IPython.Completer = Completer; |
|
384 | IPython.Completer = Completer; | |
346 |
|
385 | |||
347 | return IPython; |
|
386 | return IPython; |
General Comments 0
You need to be logged in to leave comments.
Login now