Show More
@@ -233,12 +233,10 var IPython = (function (IPython) { | |||||
233 | this.sel.dblclick(function () { |
|
233 | this.sel.dblclick(function () { | |
234 | that.pick(); |
|
234 | that.pick(); | |
235 | }); |
|
235 | }); | |
236 |
this. |
|
236 | this._handle_keydown = function (cm, event) { | |
237 | that.keydown(event); |
|
237 | that.keydown(event); | |
238 |
} |
|
238 | }; | |
239 |
this.editor.on('key |
|
239 | this.editor.on('keydown', this._handle_keydown); | |
240 | that.keypress(event); |
|
|||
241 | }); |
|
|||
242 | } |
|
240 | } | |
243 | this.sel.attr('size', Math.min(10, this.raw_result.length)); |
|
241 | this.sel.attr('size', Math.min(10, this.raw_result.length)); | |
244 |
|
242 | |||
@@ -280,30 +278,33 var IPython = (function (IPython) { | |||||
280 | Completer.prototype.close = function () { |
|
278 | Completer.prototype.close = function () { | |
281 | this.done = true; |
|
279 | this.done = true; | |
282 | $('#complete').remove(); |
|
280 | $('#complete').remove(); | |
|
281 | if (this._handle_keydown) { | |||
|
282 | this.editor.off('keydown', this._handle_keydown); | |||
|
283 | this._handle_keydown = undefined; | |||
|
284 | } | |||
283 | this.visible = false; |
|
285 | this.visible = false; | |
284 | }; |
|
286 | }; | |
285 |
|
287 | |||
286 | Completer.prototype.pick = function () { |
|
288 | Completer.prototype.pick = function () { | |
287 | this.insert(this.raw_result[this.sel[0].selectedIndex]); |
|
289 | this.insert(this.raw_result[this.sel[0].selectedIndex]); | |
288 | this.close(); |
|
290 | this.close(); | |
289 | var that = this; |
|
|||
290 | }; |
|
291 | }; | |
291 |
|
292 | |||
292 | Completer.prototype.keydown = function (event) { |
|
293 | Completer.prototype.keydown = function (event) { | |
|
294 | console.log(event); | |||
293 | var code = event.keyCode; |
|
295 | var code = event.keyCode; | |
294 | var that = this; |
|
296 | var that = this; | |
|
297 | if (!this.visible) return; | |||
295 |
|
298 | |||
296 | // Enter |
|
299 | // Enter | |
297 | if (code == keycodes.enter) { |
|
300 | if (code == keycodes.enter) { | |
298 | CodeMirror.e_stop(event); |
|
301 | event.stopPropagation(); | |
|
302 | event.codemirrorIgnore = true; | |||
299 | this.pick(); |
|
303 | this.pick(); | |
300 | } |
|
|||
301 | // Escape or backspace |
|
304 | // Escape or backspace | |
302 | else if (code == keycodes.esc) { |
|
305 | } else if (code == keycodes.esc || code == keycodes.backspace) { | |
303 | CodeMirror.e_stop(event); |
|
306 | event.stopPropagation(); | |
304 | this.close(); |
|
307 | event.codemirrorIgnore = true; | |
305 |
|
||||
306 | } else if (code == keycodes.backspace) { |
|
|||
307 | this.close(); |
|
308 | this.close(); | |
308 | } else if (code == keycodes.tab) { |
|
309 | } else if (code == keycodes.tab) { | |
309 | //all the fastforwarding operation, |
|
310 | //all the fastforwarding operation, | |
@@ -315,7 +316,8 var IPython = (function (IPython) { | |||||
315 | this.insert(sh); |
|
316 | this.insert(sh); | |
316 | } |
|
317 | } | |
317 | this.close(); |
|
318 | this.close(); | |
318 |
|
|
319 | event.codemirrorIgnore = true; | |
|
320 | event.stopPropagation(); | |||
319 | //reinvoke self |
|
321 | //reinvoke self | |
320 | setTimeout(function () { |
|
322 | setTimeout(function () { | |
321 | that.carry_on_completion(); |
|
323 | that.carry_on_completion(); | |
@@ -324,31 +326,20 var IPython = (function (IPython) { | |||||
324 | // need to do that to be able to move the arrow |
|
326 | // need to do that to be able to move the arrow | |
325 | // when on the first or last line ofo a code cell |
|
327 | // when on the first or last line ofo a code cell | |
326 | event.stopPropagation(); |
|
328 | event.stopPropagation(); | |
327 | } |
|
329 | event.codemirrorIgnore = true; | |
328 | }; |
|
|||
329 |
|
||||
330 | Completer.prototype.keypress = function (event) { |
|
|||
331 | // FIXME: This is a band-aid. |
|
|||
332 | // on keypress, trigger insertion of a single character. |
|
|||
333 | // This simulates the old behavior of completion as you type, |
|
|||
334 | // before events were disconnected and CodeMirror stopped |
|
|||
335 | // receiving events while the completer is focused. |
|
|||
336 | if (!this.visible) return; |
|
|||
337 |
|
330 | |||
338 | var that = this; |
|
331 | var options = this.sel.find('option'); | |
339 | var code = event.keyCode; |
|
332 | var index = this.sel[0].selectedIndex; | |
340 |
|
333 | if (code == keycodes.up) { | ||
341 | // don't handle keypress if it's not a character (arrows on FF) |
|
334 | index--; | |
342 | // or ENTER/TAB |
|
335 | } | |
343 | if (event.charCode === 0 || |
|
336 | if (code == keycodes.down) { | |
344 | code == keycodes.enter || |
|
337 | index++; | |
345 | code == keycodes.tab |
|
338 | } | |
346 | ) return; |
|
339 | index = Math.min(Math.max(index, 0), options.length-1); | |
347 |
|
340 | console.log('compl set index', index); | ||
348 | this.close(); |
|
341 | this.sel[0].selectedIndex = index; | |
349 | setTimeout(function () { |
|
342 | } | |
350 | that.carry_on_completion(); |
|
|||
351 | }, 50); |
|
|||
352 | }; |
|
343 | }; | |
353 |
|
344 | |||
354 | IPython.Completer = Completer; |
|
345 | IPython.Completer = Completer; |
@@ -2,23 +2,22 | |||||
2 | // Check for errors with up and down arrow presses in a non-empty notebook. |
|
2 | // Check for errors with up and down arrow presses in a non-empty notebook. | |
3 | // |
|
3 | // | |
4 | casper.notebook_test(function () { |
|
4 | casper.notebook_test(function () { | |
5 |
|
|
5 | this.then(function(){ | |
6 | IPython.notebook.command_mode(); |
|
6 | var result = this.evaluate(function() { | |
7 |
|
|
7 | IPython.notebook.command_mode(); | |
8 | IPython.keyboard.trigger_keydown('b'); |
|
8 | pos0 = IPython.notebook.get_selected_index(); | |
9 |
|
|
9 | IPython.keyboard.trigger_keydown('b'); | |
10 | IPython.keyboard.trigger_keydown('b'); |
|
10 | pos1 = IPython.notebook.get_selected_index(); | |
11 |
|
|
11 | IPython.keyboard.trigger_keydown('b'); | |
12 | // Simulate the "up arrow" and "down arrow" keys. |
|
12 | pos2 = IPython.notebook.get_selected_index(); | |
13 | IPython.keyboard.trigger_keydown('up'); |
|
13 | // Simulate the "up arrow" and "down arrow" keys. | |
14 | pos3 = IPython.notebook.get_selected_index(); |
|
14 | IPython.keyboard.trigger_keydown('up'); | |
15 | IPython.keyboard.trigger_keydown('down'); |
|
15 | pos3 = IPython.notebook.get_selected_index(); | |
16 | pos4 = IPython.notebook.get_selected_index(); |
|
16 | IPython.keyboard.trigger_keydown('down'); | |
17 | return pos0 == 0 && |
|
17 | pos4 = IPython.notebook.get_selected_index(); | |
18 | pos1 == 1 && |
|
18 | return [pos0, pos1, pos2, pos3, pos4]; | |
19 | pos2 == 2 && |
|
19 | }); | |
20 | pos3 == 1 && |
|
20 | this.test.assertEquals(result, [0, 1, 2, 1, 2], 'Up/down arrow okay in non-empty notebook.'); | |
21 | pos4 == 2; |
|
|||
22 | }); |
|
21 | }); | |
23 | this.test.assertTrue(result, 'Up/down arrow okay in non-empty notebook.'); |
|
22 | ||
24 | }); |
|
23 | }); |
@@ -25,7 +25,7 casper.notebook_test(function () { | |||||
25 | this.then(function () { |
|
25 | this.then(function () { | |
26 | var output = this.get_output_cell(0); |
|
26 | var output = this.get_output_cell(0); | |
27 | this.test.assert(messages.length > 0, "Captured log message"); |
|
27 | this.test.assert(messages.length > 0, "Captured log message"); | |
28 |
this.test.assertEquals(messages[messages.length-1], "Invalid type for image/png |
|
28 | this.test.assertEquals(messages[messages.length-1].splice(0, 26), "Invalid type for image/png", "Logged Invalid type message"); | |
29 | this.test.assertEquals(output['image/png'], undefined, "Non-string png data was stripped"); |
|
29 | this.test.assertEquals(output['image/png'], undefined, "Non-string png data was stripped"); | |
30 | this.test.assertEquals(output['text/plain'], '5', "text data is fine"); |
|
30 | this.test.assertEquals(output['text/plain'], '5', "text data is fine"); | |
31 | }); |
|
31 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now