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