##// END OF EJS Templates
as you type Completer, propagate event by hand...
Matthias BUSSONNIER -
Show More
@@ -318,21 +318,23 b' var IPython = (function (IPython) {'
318 };
318 };
319
319
320 // insert the given text and exit the completer
320 // insert the given text and exit the completer
321 var insert = function (selected_text) {
321 var insert = function (selected_text, event) {
322 that.code_mirror.replaceRange(
322 that.code_mirror.replaceRange(
323 selected_text,
323 selected_text,
324 {line: cur.line, ch: (cur.ch-matched_text.length)},
324 {line: cur.line, ch: (cur.ch-matched_text.length)},
325 {line: cur.line, ch: cur.ch}
325 {line: cur.line, ch: cur.ch}
326 );
326 );
327 if(event != null){
327 event.stopPropagation();
328 event.stopPropagation();
328 event.preventDefault();
329 event.preventDefault();
330 }
329 close();
331 close();
330 setTimeout(function(){that.code_mirror.focus();}, 50);
332 setTimeout(function(){that.code_mirror.focus();}, 50);
331 };
333 };
332
334
333 // insert the curent highlited selection and exit
335 // insert the curent highlited selection and exit
334 var pick = function () {
336 var pick = function () {
335 insert(select.val()[0]);
337 insert(select.val()[0],null);
336 };
338 };
337
339
338
340
@@ -340,14 +342,22 b' var IPython = (function (IPython) {'
340 // matches, update the pseuso typing field. autopick insert match if
342 // matches, update the pseuso typing field. autopick insert match if
341 // only one left, in no matches (anymore) dismiss itself by pasting
343 // only one left, in no matches (anymore) dismiss itself by pasting
342 // what the user have typed until then
344 // what the user have typed until then
343 var complete_with = function(matches,typed_text,autopick)
345 var complete_with = function(matches,typed_text,autopick,event)
344 {
346 {
345 // If autopick an only one match, past.
347 // If autopick an only one match, past.
346 // Used to 'pick' when pressing tab
348 // Used to 'pick' when pressing tab
347 if (matches.length < 1) {
349 if (matches.length < 1) {
348 insert(typed_text);
350 insert(typed_text,event);
351 if(event !=null){
352 event.stopPropagation();
353 event.preventDefault();
354 }
349 } else if (autopick && matches.length==1) {
355 } else if (autopick && matches.length==1) {
350 insert(matches[0]);
356 insert(matches[0],event);
357 if(event !=null){
358 event.stopPropagation();
359 event.preventDefault();
360 }
351 }
361 }
352 //clear the previous completion if any
362 //clear the previous completion if any
353 complete.children().children().remove();
363 complete.children().children().remove();
@@ -381,7 +391,7 b' var IPython = (function (IPython) {'
381 // the same letter and complete if necessary
391 // the same letter and complete if necessary
382 fastForward = sharedStart(matches)
392 fastForward = sharedStart(matches)
383 typed_characters= fastForward.substr(matched_text.length);
393 typed_characters= fastForward.substr(matched_text.length);
384 complete_with(matches,matched_text+typed_characters,true);
394 complete_with(matches,matched_text+typed_characters,true,null);
385 filterd=matches;
395 filterd=matches;
386 // Give focus to select, and make it filter the match as the user type
396 // Give focus to select, and make it filter the match as the user type
387 // by filtering the previous matches. Called by .keypress and .keydown
397 // by filtering the previous matches. Called by .keypress and .keydown
@@ -407,8 +417,8 b' var IPython = (function (IPython) {'
407 // but we want the default action.
417 // but we want the default action.
408 event.stopPropagation();
418 event.stopPropagation();
409 //} else if ( key.isCompSymbol(code)|| (code==key.backspace)||(code==key.tab && down)){
419 //} else if ( key.isCompSymbol(code)|| (code==key.backspace)||(code==key.tab && down)){
410 } else if ( (code==key.backspace)||(code==key.tab) || press || key.isCompSymbol(code)){
420 } else if ( (code==key.backspace)||(code==key.tab && down) || press || key.isCompSymbol(code)){
411 if((code != key.backspace) && (code != key.tab) && press)
421 if( key.isCompSymbol(code) && press)
412 {
422 {
413 var newchar = String.fromCharCode(code);
423 var newchar = String.fromCharCode(code);
414 typed_characters=typed_characters+newchar;
424 typed_characters=typed_characters+newchar;
@@ -419,22 +429,22 b' var IPython = (function (IPython) {'
419 autopick=true;
429 autopick=true;
420 event.stopPropagation();
430 event.stopPropagation();
421 event.preventDefault();
431 event.preventDefault();
422 } else if (code == key.backspace) {
432 } else if (code == key.backspace && down) {
423 // cancel if user have erase everything, otherwise decrease
433 // cancel if user have erase everything, otherwise decrease
424 // what we filter with
434 // what we filter with
425 if (typed_characters.length <= 0)
435 if (typed_characters.length <= 0)
426 {
436 {
427 insert(matched_text)
437 insert(matched_text,event)
428 }
438 }
429 typed_characters=typed_characters.substr(0,typed_characters.length-1);
439 typed_characters=typed_characters.substr(0,typed_characters.length-1);
430 }
440 }else{return}
431 re = new RegExp("^"+"\%?"+matched_text+typed_characters,"");
441 re = new RegExp("^"+"\%?"+matched_text+typed_characters,"");
432 filterd = matches.filter(function(x){return re.test(x)});
442 filterd = matches.filter(function(x){return re.test(x)});
433 complete_with(filterd,matched_text+typed_characters,autopick);
443 complete_with(filterd,matched_text+typed_characters,autopick,event);
434 } else if(down){ // abort only on .keydown
444 } else if(down){ // abort only on .keydown
435 // abort with what the user have pressed until now
445 // abort with what the user have pressed until now
436 console.log('aborting with keycode : '+code+' is down :'+down);
446 console.log('aborting with keycode : '+code+' is down :'+down);
437 insert(matched_text+typed_characters);
447 insert(matched_text+typed_characters,event);
438 }
448 }
439 }
449 }
440 select.keydown(function (event) {
450 select.keydown(function (event) {
General Comments 0
You need to be logged in to leave comments. Login now