Show More
@@ -233,6 +233,14 var IPython = (function (IPython) { | |||
|
233 | 233 | CodeCell.prototype.finish_completing = function (matched_text, matches) { |
|
234 | 234 | |
|
235 | 235 | // smart completion, sort kwarg ending with '=' |
|
236 | var key = { tab:9, | |
|
237 | esc:8, | |
|
238 | space:13, | |
|
239 | shift:16, | |
|
240 | enter:32, | |
|
241 | // _ is 189 | |
|
242 | isCompSymbol : function (code) {return ((code>64 && code <=122)|| code == 189)} | |
|
243 | } | |
|
236 | 244 | var newm = new Array(); |
|
237 | 245 | if(this.notebook.smart_completer) |
|
238 | 246 | { |
@@ -320,22 +328,20 var IPython = (function (IPython) { | |||
|
320 | 328 | insert(select.val()[0]); |
|
321 | 329 | }; |
|
322 | 330 | |
|
323 | // if only one match, complete to it, don't ask user | |
|
324 | if (matches.length === 1) { | |
|
325 | insert(matches[0]); | |
|
326 | return; | |
|
327 | }; | |
|
328 | ||
|
329 | 331 | |
|
330 | 332 | // Define function to clear the completer, refill it with the new |
|
331 | 333 | // matches, update the pseuso typing field. Note that this is case |
|
332 | 334 | // insensitive for now |
|
333 | var complete_with = function(matches,typed_text) | |
|
335 | var complete_with = function(matches,typed_text,autopick) | |
|
334 | 336 | { |
|
335 | //clear the previous completion if any | |
|
337 | // If autopick an only one match, past. | |
|
338 | // Used to 'pick' when pressing tab | |
|
336 | 339 | if (matches.length < 1) { |
|
337 | 340 | insert(typed_text); |
|
341 | } else if (autopick && matches.length==1) { | |
|
342 | insert(matches[0]); | |
|
338 | 343 | } |
|
344 | //clear the previous completion if any | |
|
339 | 345 | complete.children().children().remove(); |
|
340 | 346 | $('#asyoutype').text(typed_text); |
|
341 | 347 | select=$('#asyoutypeselect'); |
@@ -364,25 +370,25 var IPython = (function (IPython) { | |||
|
364 | 370 | $('body').append(complete); |
|
365 | 371 | |
|
366 | 372 | //do a first actual completion |
|
367 | complete_with(matches,matched_text); | |
|
368 | ||
|
373 | fastForward = sharedStart(matches) | |
|
374 | typed_characters= fastForward.substr(matched_text.length); | |
|
375 | complete_with(matches,matched_text+typed_characters,true); | |
|
376 | filterd=matches; | |
|
369 | 377 | // Give focus to select, and make it filter the match as the user type |
|
370 | 378 | // by filtering the previous matches |
|
371 | typed_characters = ""; | |
|
372 | 379 | var downandpress = function (event,press_or_down) { |
|
380 | var code = event.which; | |
|
381 | var autopick = false; // auto 'pick' if only one match | |
|
373 | 382 | if (press_or_down === 0){ |
|
374 | press=true; | |
|
375 | down=false; | |
|
383 | press=true; down=false; //Are we called from keypress or keydown | |
|
376 | 384 | } else if (press_or_down == 1){ |
|
377 | press=false; | |
|
378 | down=true; | |
|
385 | press=false; down=true; | |
|
379 | 386 | } |
|
380 |
|
|
|
381 | if (code === 16) { | |
|
387 | if (code === key.shift) { | |
|
382 | 388 | // nothing on Shift |
|
383 | 389 | return; |
|
384 | 390 | } |
|
385 |
if (code === |
|
|
391 | if (code === key.space || code === key.enter) { | |
|
386 | 392 | // Pressing SPACE or ENTER will cause a pick |
|
387 | 393 | event.stopPropagation(); |
|
388 | 394 | event.preventDefault(); |
@@ -391,20 +397,21 var IPython = (function (IPython) { | |||
|
391 | 397 | // We don't want the document keydown handler to handle UP/DOWN, |
|
392 | 398 | // but we want the default action. |
|
393 | 399 | event.stopPropagation(); |
|
394 |
} else if ( |
|
|
400 | //} else if ( key.isCompSymbol(code)|| (code==key.backspace)||(code==key.tab && down)){ | |
|
401 | } else if ( (code==key.backspace)||(code==key.tab) || press || key.isCompSymbol(code)){ | |
|
395 | 402 | // issues with _-.. on chrome at least |
|
396 |
if(code != |
|
|
403 | if((code != key.backspace) && (code != key.tab) && press) | |
|
397 | 404 | { |
|
398 | 405 | var newchar = String.fromCharCode(code); |
|
399 | 406 | typed_characters=typed_characters+newchar; |
|
400 |
} else if (code == |
|
|
407 | } else if (code == key.tab) { | |
|
401 | 408 | fastForward = sharedStart(filterd) |
|
402 | 409 | ffsub = fastForward.substr(matched_text.length+typed_characters.length); |
|
403 | 410 | typed_characters=typed_characters+ffsub; |
|
404 | console.log("Fast forded by :"+ffsub); | |
|
411 | autopick=true; | |
|
405 | 412 | event.stopPropagation(); |
|
406 | 413 | event.preventDefault(); |
|
407 |
} else if (code == |
|
|
414 | } else if (code == key.backspace) { | |
|
408 | 415 | // 8 is backspace remove 1 char cancel if |
|
409 | 416 | // user have erase everything, otherwise |
|
410 | 417 | // decrease what we filter with |
@@ -416,10 +423,10 var IPython = (function (IPython) { | |||
|
416 | 423 | } |
|
417 | 424 | re = new RegExp("^"+"\%?"+matched_text+typed_characters,""); |
|
418 | 425 | filterd= matches.filter(function(x){return re.test(x)}); |
|
419 | complete_with(filterd,matched_text+typed_characters); | |
|
426 | complete_with(filterd,matched_text+typed_characters,autopick); | |
|
420 | 427 | } else if(down){ // abort only on press |
|
421 | 428 | // abort with what the user have pressed until now |
|
422 | console.log('aborting with keycode : '+code); | |
|
429 | console.log('aborting with keycode : '+code+press); | |
|
423 | 430 | insert(matched_text+typed_characters); |
|
424 | 431 | } |
|
425 | 432 | } |
General Comments 0
You need to be logged in to leave comments.
Login now