##// END OF EJS Templates
completer update code-miror on the fly...
Matthias BUSSONNIER -
Show More
@@ -419,6 +419,11 b' div.text_cell_render {'
419 419 min-height:50px;
420 420 }
421 421
422 /*fixed part of the completion*/
423 .completions p b{
424 font-weight:bold;
425 }
426
422 427 .completions p{
423 428 background: #DDF;
424 429 /*outline: none;
@@ -241,19 +241,19 b' var IPython = (function (IPython) {'
241 241 var key = { tab:9,
242 242 esc:27,
243 243 backspace:8,
244 space:13,
244 space:32,
245 245 shift:16,
246 enter:32,
246 enter:13,
247 247 // _ is 95
248 248 isCompSymbol : function (code)
249 249 {
250 return (code > 64 && code <= 90)
250 return (code > 64 && code <= 90)
251 251 || (code >= 97 && code <= 122)
252 252 || (code == 95)
253 253 },
254 254 dismissAndAppend : function (code)
255 255 {
256 chararr = ['(',')','[',']','+','-','/','\\','.'];
256 chararr = ['(',')','[',']','+','-','/','\\','.',' '];
257 257 codearr = chararr.map(function(x){return x.charCodeAt(0)});
258 258 return jQuery.inArray(code, codearr) != -1;
259 259 }
@@ -330,17 +330,23 b' var IPython = (function (IPython) {'
330 330 that.completion_cursor = null;
331 331 };
332 332
333 // insert the given text and exit the completer
334 var insert = function (selected_text, event) {
333 // update codemirror with the typed text
334 prev = matched_text
335 var update = function (inserted_text, event) {
335 336 that.code_mirror.replaceRange(
336 selected_text,
337 inserted_text,
337 338 {line: cur.line, ch: (cur.ch-matched_text.length)},
338 {line: cur.line, ch: cur.ch}
339 {line: cur.line, ch: (cur.ch+prev.length-matched_text.length)}
339 340 );
341 prev = inserted_text
340 342 if(event != null){
341 343 event.stopPropagation();
342 344 event.preventDefault();
343 345 }
346 };
347 // insert the given text and exit the completer
348 var insert = function (selected_text, event) {
349 update(selected_text)
344 350 close();
345 351 setTimeout(function(){that.code_mirror.focus();}, 50);
346 352 };
@@ -373,8 +379,9 b' var IPython = (function (IPython) {'
373 379 }
374 380 }
375 381 //clear the previous completion if any
382 update(typed_text,event);
376 383 complete.children().children().remove();
377 $('#asyoutype').text(typed_text);
384 $('#asyoutype').html("<b>"+matched_text+"</b>"+typed_text.substr(matched_text.length));
378 385 select = $('#asyoutypeselect');
379 386 for (var i = 0; i<matches.length; ++i) {
380 387 select.append($('<option/>').html(matches[i]));
@@ -385,7 +392,7 b' var IPython = (function (IPython) {'
385 392 // create html for completer
386 393 var complete = $('<div/>').addClass('completions');
387 394 complete.attr('id','complete');
388 complete.append($('<p/>').attr('id', 'asyoutype').html(matched_text));//pseudo input field
395 complete.append($('<p/>').attr('id', 'asyoutype').html('<b>fixed part</b>user part'));//pseudo input field
389 396
390 397 var select = $('<select/>').attr('multiple','true');
391 398 select.attr('id', 'asyoutypeselect')
@@ -426,8 +433,8 b' var IPython = (function (IPython) {'
426 433 insert(matched_text+typed_characters,event);
427 434 return
428 435 }
429 if (code === key.space || code === key.enter) {
430 // Pressing SPACE or ENTER will cause a pick
436 if (code === key.enter) {
437 // Pressing ENTER will cause a pick
431 438 event.stopPropagation();
432 439 event.preventDefault();
433 440 pick();
@@ -445,11 +452,10 b' var IPython = (function (IPython) {'
445 452 ffsub = fastForward.substr(matched_text.length+typed_characters.length);
446 453 typed_characters = typed_characters+ffsub;
447 454 autopick = true;
448 event.stopPropagation();
449 event.preventDefault();
450 455 } else if (code == key.backspace && down) {
451 456 // cancel if user have erase everything, otherwise decrease
452 457 // what we filter with
458 event.preventDefault();
453 459 if (typed_characters.length <= 0)
454 460 {
455 461 insert(matched_text,event)
@@ -465,10 +471,12 b' var IPython = (function (IPython) {'
465 471 re = new RegExp("^"+"\%?"+matched_text+typed_characters,"");
466 472 filterd = matches.filter(function(x){return re.test(x)});
467 473 complete_with(filterd,matched_text+typed_characters,autopick,event);
468 } else if( press || code == key.esc){ // abort only on .keypress or esc
474 } else if( code == key.esc) {
475 // dismiss the completer and go back to before invoking it
476 insert(matched_text,event);
477 } else if( press ){ // abort only on .keypress or esc
469 478 // abort with what the user have pressed until now
470 479 console.log('aborting with keycode : '+code+' is down :'+down);
471 insert(matched_text+typed_characters,event);
472 480 }
473 481 }
474 482 select.keydown(function (event) {
General Comments 0
You need to be logged in to leave comments. Login now