##// END OF EJS Templates
tidy up code
Matthias BUSSONNIER -
Show More
@@ -231,16 +231,22 b' var IPython = (function (IPython) {'
231
231
232 // As you type completer
232 // As you type completer
233 CodeCell.prototype.finish_completing = function (matched_text, matches) {
233 CodeCell.prototype.finish_completing = function (matched_text, matches) {
234 //return if not completing or nothing to complete
235 if (!this.is_completing || matches.length === 0) {return;}
234
236
235 // smart completion, sort kwarg ending with '='
237 // for later readability
236 var key = { tab:9,
238 var key = { tab:9,
237 esc:8,
239 esc:27,
240 backspace:8,
238 space:13,
241 space:13,
239 shift:16,
242 shift:16,
240 enter:32,
243 enter:32,
241 // _ is 189
244 // _ is 189
242 isCompSymbol : function (code) {return ((code>64 && code <=122)|| code == 189)}
245 isCompSymbol : function (code)
246 {return ((code>64 && code <=122)|| code == 189)}
243 }
247 }
248
249 // smart completion, sort kwarg ending with '='
244 var newm = new Array();
250 var newm = new Array();
245 if(this.notebook.smart_completer)
251 if(this.notebook.smart_completer)
246 {
252 {
@@ -256,21 +262,21 b' var IPython = (function (IPython) {'
256 }
262 }
257 // end sort kwargs
263 // end sort kwargs
258
264
265 // give common prefix of a array of string
259 function sharedStart(A){
266 function sharedStart(A){
260 if(A.length > 1 ){
267 if(A.length > 1 ){
261 var tem1, tem2, s, A= A.slice(0).sort();
268 var tem1, tem2, s, A= A.slice(0).sort();
262 tem1= A[0];
269 tem1= A[0];
263 s= tem1.length;
270 s= tem1.length;
264 tem2= A.pop();
271 tem2= A.pop();
265 while(s && tem2.indexOf(tem1)== -1){
272 while(s && tem2.indexOf(tem1)== -1){
266 tem1= tem1.substring(0, --s);
273 tem1= tem1.substring(0, --s);
267 }
274 }
268 return tem1;
275 return tem1;
269 }
276 }
270 return "";
277 return "";
271 }
278 }
272
279
273 if (!this.is_completing || matches.length === 0) {return;}
274
280
275 //try to check if the user is typing tab at least twice after a word
281 //try to check if the user is typing tab at least twice after a word
276 // and completion is "done"
282 // and completion is "done"
@@ -294,7 +300,7 b' var IPython = (function (IPython) {'
294 this.npressed=0;
300 this.npressed=0;
295 }
301 }
296 // end fallback on tooltip
302 // end fallback on tooltip
297
303 //==================================
298 // Real completion logic start here
304 // Real completion logic start here
299 var that = this;
305 var that = this;
300 var cur = this.completion_cursor;
306 var cur = this.completion_cursor;
@@ -330,8 +336,9 b' var IPython = (function (IPython) {'
330
336
331
337
332 // Define function to clear the completer, refill it with the new
338 // Define function to clear the completer, refill it with the new
333 // matches, update the pseuso typing field. Note that this is case
339 // matches, update the pseuso typing field. autopick insert match if
334 // insensitive for now
340 // only one left, in no matches (anymore) dismiss itself by pasting
341 // what the user have typed until then
335 var complete_with = function(matches,typed_text,autopick)
342 var complete_with = function(matches,typed_text,autopick)
336 {
343 {
337 // If autopick an only one match, past.
344 // If autopick an only one match, past.
@@ -369,13 +376,14 b' var IPython = (function (IPython) {'
369
376
370 $('body').append(complete);
377 $('body').append(complete);
371
378
372 //do a first actual completion
379 // So a first actual completion. see if all the completion start wit
380 // the same letter and complete if necessary
373 fastForward = sharedStart(matches)
381 fastForward = sharedStart(matches)
374 typed_characters= fastForward.substr(matched_text.length);
382 typed_characters= fastForward.substr(matched_text.length);
375 complete_with(matches,matched_text+typed_characters,true);
383 complete_with(matches,matched_text+typed_characters,true);
376 filterd=matches;
384 filterd=matches;
377 // Give focus to select, and make it filter the match as the user type
385 // Give focus to select, and make it filter the match as the user type
378 // by filtering the previous matches
386 // by filtering the previous matches. Called by .keypress and .keydown
379 var downandpress = function (event,press_or_down) {
387 var downandpress = function (event,press_or_down) {
380 var code = event.which;
388 var code = event.which;
381 var autopick = false; // auto 'pick' if only one match
389 var autopick = false; // auto 'pick' if only one match
@@ -399,8 +407,7 b' var IPython = (function (IPython) {'
399 event.stopPropagation();
407 event.stopPropagation();
400 //} else if ( key.isCompSymbol(code)|| (code==key.backspace)||(code==key.tab && down)){
408 //} else if ( key.isCompSymbol(code)|| (code==key.backspace)||(code==key.tab && down)){
401 } else if ( (code==key.backspace)||(code==key.tab) || press || key.isCompSymbol(code)){
409 } else if ( (code==key.backspace)||(code==key.tab) || press || key.isCompSymbol(code)){
402 // issues with _-.. on chrome at least
410 if((code != key.backspace) && (code != key.tab) && press)
403 if((code != key.backspace) && (code != key.tab) && press)
404 {
411 {
405 var newchar = String.fromCharCode(code);
412 var newchar = String.fromCharCode(code);
406 typed_characters=typed_characters+newchar;
413 typed_characters=typed_characters+newchar;
@@ -412,9 +419,8 b' var IPython = (function (IPython) {'
412 event.stopPropagation();
419 event.stopPropagation();
413 event.preventDefault();
420 event.preventDefault();
414 } else if (code == key.backspace) {
421 } else if (code == key.backspace) {
415 // 8 is backspace remove 1 char cancel if
422 // cancel if user have erase everything, otherwise decrease
416 // user have erase everything, otherwise
423 // what we filter with
417 // decrease what we filter with
418 if (typed_characters.length <= 0)
424 if (typed_characters.length <= 0)
419 {
425 {
420 insert(matched_text)
426 insert(matched_text)
@@ -422,11 +428,11 b' var IPython = (function (IPython) {'
422 typed_characters=typed_characters.substr(0,typed_characters.length-1);
428 typed_characters=typed_characters.substr(0,typed_characters.length-1);
423 }
429 }
424 re = new RegExp("^"+"\%?"+matched_text+typed_characters,"");
430 re = new RegExp("^"+"\%?"+matched_text+typed_characters,"");
425 filterd= matches.filter(function(x){return re.test(x)});
431 filterd = matches.filter(function(x){return re.test(x)});
426 complete_with(filterd,matched_text+typed_characters,autopick);
432 complete_with(filterd,matched_text+typed_characters,autopick);
427 } else if(down){ // abort only on press
433 } else if(down){ // abort only on .keydown
428 // abort with what the user have pressed until now
434 // abort with what the user have pressed until now
429 console.log('aborting with keycode : '+code+press);
435 console.log('aborting with keycode : '+code+' is down :'+down);
430 insert(matched_text+typed_characters);
436 insert(matched_text+typed_characters);
431 }
437 }
432 }
438 }
General Comments 0
You need to be logged in to leave comments. Login now