Show More
@@ -245,6 +245,13 b' var IPython = (function (IPython) {' | |||||
245 |
|
245 | |||
246 | // As you type completer |
|
246 | // As you type completer | |
247 | CodeCell.prototype.finish_completing = function (matched_text, matches) { |
|
247 | CodeCell.prototype.finish_completing = function (matched_text, matches) { | |
|
248 | if(matched_text[0]=='%'){ | |||
|
249 | completing_from_magic = true; | |||
|
250 | completing_to_magic = false; | |||
|
251 | } else { | |||
|
252 | completing_from_magic = false; | |||
|
253 | completing_to_magic = false; | |||
|
254 | } | |||
248 | //return if not completing or nothing to complete |
|
255 | //return if not completing or nothing to complete | |
249 | if (!this.is_completing || matches.length === 0) {return;} |
|
256 | if (!this.is_completing || matches.length === 0) {return;} | |
250 |
|
257 | |||
@@ -289,7 +296,8 b' var IPython = (function (IPython) {' | |||||
289 |
|
296 | |||
290 | // give common prefix of a array of string |
|
297 | // give common prefix of a array of string | |
291 | function sharedStart(A){ |
|
298 | function sharedStart(A){ | |
292 | if(A.length == 1){return A[0]} |
|
299 | shared=''; | |
|
300 | if(A.length == 1){shared=A[0]} | |||
293 | if(A.length > 1 ){ |
|
301 | if(A.length > 1 ){ | |
294 | var tem1, tem2, s, A = A.slice(0).sort(); |
|
302 | var tem1, tem2, s, A = A.slice(0).sort(); | |
295 | tem1 = A[0]; |
|
303 | tem1 = A[0]; | |
@@ -298,9 +306,15 b' var IPython = (function (IPython) {' | |||||
298 | while(s && tem2.indexOf(tem1) == -1){ |
|
306 | while(s && tem2.indexOf(tem1) == -1){ | |
299 | tem1 = tem1.substring(0, --s); |
|
307 | tem1 = tem1.substring(0, --s); | |
300 | } |
|
308 | } | |
301 |
|
|
309 | shared = tem1; | |
|
310 | } | |||
|
311 | if (shared[0] == '%' && !completing_from_magic) | |||
|
312 | { | |||
|
313 | shared = shared.substr(1); | |||
|
314 | return [shared, true]; | |||
|
315 | } else { | |||
|
316 | return [shared, false]; | |||
302 | } |
|
317 | } | |
303 | return ""; |
|
|||
304 | } |
|
318 | } | |
305 |
|
319 | |||
306 |
|
320 | |||
@@ -377,8 +391,13 b' var IPython = (function (IPython) {' | |||||
377 | { |
|
391 | { | |
378 | // If autopick an only one match, past. |
|
392 | // If autopick an only one match, past. | |
379 | // Used to 'pick' when pressing tab |
|
393 | // Used to 'pick' when pressing tab | |
|
394 | var prefix = ''; | |||
|
395 | if(completing_to_magic && !completing_from_magic) | |||
|
396 | { | |||
|
397 | prefix='%'; | |||
|
398 | } | |||
380 | if (matches.length < 1) { |
|
399 | if (matches.length < 1) { | |
381 | insert(typed_text,event); |
|
400 | insert(prefix+typed_text,event); | |
382 | if(event != null){ |
|
401 | if(event != null){ | |
383 | event.stopPropagation(); |
|
402 | event.stopPropagation(); | |
384 | event.preventDefault(); |
|
403 | event.preventDefault(); | |
@@ -389,11 +408,12 b' var IPython = (function (IPython) {' | |||||
389 | event.stopPropagation(); |
|
408 | event.stopPropagation(); | |
390 | event.preventDefault(); |
|
409 | event.preventDefault(); | |
391 | } |
|
410 | } | |
|
411 | return; | |||
392 | } |
|
412 | } | |
393 | //clear the previous completion if any |
|
413 | //clear the previous completion if any | |
394 | update(typed_text,event); |
|
414 | update(prefix+typed_text,event); | |
395 | complete.children().children().remove(); |
|
415 | complete.children().children().remove(); | |
396 | $('#asyoutype').html("<b>"+matched_text+"</b>"+typed_text.substr(matched_text.length)); |
|
416 | $('#asyoutype').html("<b>"+prefix+matched_text+"</b>"+typed_text.substr(matched_text.length)); | |
397 | select = $('#asyoutypeselect'); |
|
417 | select = $('#asyoutypeselect'); | |
398 | for (var i = 0; i<matches.length; ++i) { |
|
418 | for (var i = 0; i<matches.length; ++i) { | |
399 | select.append($('<option/>').html(matches[i])); |
|
419 | select.append($('<option/>').html(matches[i])); | |
@@ -421,7 +441,9 b' var IPython = (function (IPython) {' | |||||
421 |
|
441 | |||
422 | // So a first actual completion. see if all the completion start wit |
|
442 | // So a first actual completion. see if all the completion start wit | |
423 | // the same letter and complete if necessary |
|
443 | // the same letter and complete if necessary | |
424 |
f |
|
444 | ff = sharedStart(matches) | |
|
445 | fastForward = ff[0]; | |||
|
446 | completing_to_magic = ff[1]; | |||
425 | typed_characters = fastForward.substr(matched_text.length); |
|
447 | typed_characters = fastForward.substr(matched_text.length); | |
426 | complete_with(matches,matched_text+typed_characters,true,null); |
|
448 | complete_with(matches,matched_text+typed_characters,true,null); | |
427 | filterd = matches; |
|
449 | filterd = matches; | |
@@ -460,7 +482,9 b' var IPython = (function (IPython) {' | |||||
460 | var newchar = String.fromCharCode(code); |
|
482 | var newchar = String.fromCharCode(code); | |
461 | typed_characters = typed_characters+newchar; |
|
483 | typed_characters = typed_characters+newchar; | |
462 | } else if (code == key.tab) { |
|
484 | } else if (code == key.tab) { | |
463 |
f |
|
485 | ff = sharedStart(matches) | |
|
486 | fastForward = ff[0]; | |||
|
487 | completing_to_magic = ff[1]; | |||
464 | ffsub = fastForward.substr(matched_text.length+typed_characters.length); |
|
488 | ffsub = fastForward.substr(matched_text.length+typed_characters.length); | |
465 | typed_characters = typed_characters+ffsub; |
|
489 | typed_characters = typed_characters+ffsub; | |
466 | autopick = true; |
|
490 | autopick = true; | |
@@ -482,6 +506,8 b' var IPython = (function (IPython) {' | |||||
482 | } |
|
506 | } | |
483 | re = new RegExp("^"+"\%?"+matched_text+typed_characters,""); |
|
507 | re = new RegExp("^"+"\%?"+matched_text+typed_characters,""); | |
484 | filterd = matches.filter(function(x){return re.test(x)}); |
|
508 | filterd = matches.filter(function(x){return re.test(x)}); | |
|
509 | ff = sharedStart(filterd); | |||
|
510 | completing_to_magic = ff[1]; | |||
485 | complete_with(filterd,matched_text+typed_characters,autopick,event); |
|
511 | complete_with(filterd,matched_text+typed_characters,autopick,event); | |
486 | } else if( code == key.esc) { |
|
512 | } else if( code == key.esc) { | |
487 | // dismiss the completer and go back to before invoking it |
|
513 | // dismiss the completer and go back to before invoking it |
General Comments 0
You need to be logged in to leave comments.
Login now