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