Show More
@@ -264,6 +264,13 b' var IPython = (function (IPython) {' | |||||
264 |
|
264 | |||
265 | // As you type completer |
|
265 | // As you type completer | |
266 | CodeCell.prototype.finish_completing = function (matched_text, matches) { |
|
266 | CodeCell.prototype.finish_completing = function (matched_text, matches) { | |
|
267 | if(matched_text[0]=='%'){ | |||
|
268 | completing_from_magic = true; | |||
|
269 | completing_to_magic = false; | |||
|
270 | } else { | |||
|
271 | completing_from_magic = false; | |||
|
272 | completing_to_magic = false; | |||
|
273 | } | |||
267 | //return if not completing or nothing to complete |
|
274 | //return if not completing or nothing to complete | |
268 | if (!this.is_completing || matches.length === 0) {return;} |
|
275 | if (!this.is_completing || matches.length === 0) {return;} | |
269 |
|
276 | |||
@@ -308,7 +315,8 b' var IPython = (function (IPython) {' | |||||
308 |
|
315 | |||
309 | // give common prefix of a array of string |
|
316 | // give common prefix of a array of string | |
310 | function sharedStart(A){ |
|
317 | function sharedStart(A){ | |
311 | if(A.length == 1){return A[0]} |
|
318 | shared=''; | |
|
319 | if(A.length == 1){shared=A[0]} | |||
312 | if(A.length > 1 ){ |
|
320 | if(A.length > 1 ){ | |
313 | var tem1, tem2, s, A = A.slice(0).sort(); |
|
321 | var tem1, tem2, s, A = A.slice(0).sort(); | |
314 | tem1 = A[0]; |
|
322 | tem1 = A[0]; | |
@@ -317,9 +325,15 b' var IPython = (function (IPython) {' | |||||
317 | while(s && tem2.indexOf(tem1) == -1){ |
|
325 | while(s && tem2.indexOf(tem1) == -1){ | |
318 | tem1 = tem1.substring(0, --s); |
|
326 | tem1 = tem1.substring(0, --s); | |
319 | } |
|
327 | } | |
320 |
|
|
328 | shared = tem1; | |
|
329 | } | |||
|
330 | if (shared[0] == '%' && !completing_from_magic) | |||
|
331 | { | |||
|
332 | shared = shared.substr(1); | |||
|
333 | return [shared, true]; | |||
|
334 | } else { | |||
|
335 | return [shared, false]; | |||
321 | } |
|
336 | } | |
322 | return ""; |
|
|||
323 | } |
|
337 | } | |
324 |
|
338 | |||
325 |
|
339 | |||
@@ -393,8 +407,13 b' var IPython = (function (IPython) {' | |||||
393 | { |
|
407 | { | |
394 | // If autopick an only one match, past. |
|
408 | // If autopick an only one match, past. | |
395 | // Used to 'pick' when pressing tab |
|
409 | // Used to 'pick' when pressing tab | |
|
410 | var prefix = ''; | |||
|
411 | if(completing_to_magic && !completing_from_magic) | |||
|
412 | { | |||
|
413 | prefix='%'; | |||
|
414 | } | |||
396 | if (matches.length < 1) { |
|
415 | if (matches.length < 1) { | |
397 | insert(typed_text,event); |
|
416 | insert(prefix+typed_text,event); | |
398 | if(event != null){ |
|
417 | if(event != null){ | |
399 | event.stopPropagation(); |
|
418 | event.stopPropagation(); | |
400 | event.preventDefault(); |
|
419 | event.preventDefault(); | |
@@ -405,11 +424,12 b' var IPython = (function (IPython) {' | |||||
405 | event.stopPropagation(); |
|
424 | event.stopPropagation(); | |
406 | event.preventDefault(); |
|
425 | event.preventDefault(); | |
407 | } |
|
426 | } | |
|
427 | return; | |||
408 | } |
|
428 | } | |
409 | //clear the previous completion if any |
|
429 | //clear the previous completion if any | |
410 | update(typed_text,event); |
|
430 | update(prefix+typed_text,event); | |
411 | complete.children().children().remove(); |
|
431 | complete.children().children().remove(); | |
412 | $('#asyoutype').html("<b>"+matched_text+"</b>"+typed_text.substr(matched_text.length)); |
|
432 | $('#asyoutype').html("<b>"+prefix+matched_text+"</b>"+typed_text.substr(matched_text.length)); | |
413 | select = $('#asyoutypeselect'); |
|
433 | select = $('#asyoutypeselect'); | |
414 | for (var i = 0; i<matches.length; ++i) { |
|
434 | for (var i = 0; i<matches.length; ++i) { | |
415 | select.append($('<option/>').html(matches[i])); |
|
435 | select.append($('<option/>').html(matches[i])); | |
@@ -437,7 +457,9 b' var IPython = (function (IPython) {' | |||||
437 |
|
457 | |||
438 | // So a first actual completion. see if all the completion start wit |
|
458 | // So a first actual completion. see if all the completion start wit | |
439 | // the same letter and complete if necessary |
|
459 | // the same letter and complete if necessary | |
440 |
f |
|
460 | ff = sharedStart(matches) | |
|
461 | fastForward = ff[0]; | |||
|
462 | completing_to_magic = ff[1]; | |||
441 | typed_characters = fastForward.substr(matched_text.length); |
|
463 | typed_characters = fastForward.substr(matched_text.length); | |
442 | complete_with(matches,matched_text+typed_characters,true,null); |
|
464 | complete_with(matches,matched_text+typed_characters,true,null); | |
443 | filterd = matches; |
|
465 | filterd = matches; | |
@@ -476,7 +498,9 b' var IPython = (function (IPython) {' | |||||
476 | var newchar = String.fromCharCode(code); |
|
498 | var newchar = String.fromCharCode(code); | |
477 | typed_characters = typed_characters+newchar; |
|
499 | typed_characters = typed_characters+newchar; | |
478 | } else if (code == key.tab) { |
|
500 | } else if (code == key.tab) { | |
479 |
f |
|
501 | ff = sharedStart(matches) | |
|
502 | fastForward = ff[0]; | |||
|
503 | completing_to_magic = ff[1]; | |||
480 | ffsub = fastForward.substr(matched_text.length+typed_characters.length); |
|
504 | ffsub = fastForward.substr(matched_text.length+typed_characters.length); | |
481 | typed_characters = typed_characters+ffsub; |
|
505 | typed_characters = typed_characters+ffsub; | |
482 | autopick = true; |
|
506 | autopick = true; | |
@@ -498,6 +522,8 b' var IPython = (function (IPython) {' | |||||
498 | } |
|
522 | } | |
499 | re = new RegExp("^"+"\%?"+matched_text+typed_characters,""); |
|
523 | re = new RegExp("^"+"\%?"+matched_text+typed_characters,""); | |
500 | filterd = matches.filter(function(x){return re.test(x)}); |
|
524 | filterd = matches.filter(function(x){return re.test(x)}); | |
|
525 | ff = sharedStart(filterd); | |||
|
526 | completing_to_magic = ff[1]; | |||
501 | complete_with(filterd,matched_text+typed_characters,autopick,event); |
|
527 | complete_with(filterd,matched_text+typed_characters,autopick,event); | |
502 | } else if (code == key.esc) { |
|
528 | } else if (code == key.esc) { | |
503 | // dismiss the completer and go back to before invoking it |
|
529 | // dismiss the completer and go back to before invoking it |
General Comments 0
You need to be logged in to leave comments.
Login now