Skip to content
This repository

As you type completer, fix on Firefox #1069

Merged
merged 1 commit into from over 2 years ago

3 participants

Matthias Bussonnier Thomas Kluyver Fernando Perez
Matthias Bussonnier
Collaborator

As you type completer is (really) broken on firefox. It insert invisible characters

This should fixed the observed bugs and keep the same behavior across browser.

Matthias Bussonnier as you type Completer, propagate event by hand
	Should fix completer behaviour on firefox...
40de69f
Thomas Kluyver
Collaborator

Seems to be working here.

I've not used the notebook since we added the as-you-type completer - it's a brilliant tool. Thanks!

Matthias Bussonnier
Collaborator

Thanks,
I couldn't have done something like that, or even think of it without all the great work you all have done !
Maybe this 0.12 will finally convince some people I work with to consider other tool than matlab !

Fernando Perez
Owner

Several people have confirmed this fixes it, merging. Thanks for the quick response, @Carreau!

Fernando Perez fperez merged commit e89be0c into from November 30, 2011
Fernando Perez fperez closed this November 30, 2011
Fernando Perez fperez referenced this pull request from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 30, 2011
Matthias Bussonnier as you type Completer, propagate event by hand
	Should fix completer behaviour on firefox...
40de69f
This page is out of date. Refresh to see the latest.
40  IPython/frontend/html/notebook/static/js/codecell.js
@@ -318,21 +318,23 @@ var IPython = (function (IPython) {
318 318
         };
319 319
 
320 320
         // insert the given text and exit the completer
321  
-        var insert = function (selected_text) {
  321
+        var insert = function (selected_text, event) {
322 322
             that.code_mirror.replaceRange(
323 323
                 selected_text,
324 324
                 {line: cur.line, ch: (cur.ch-matched_text.length)},
325 325
                 {line: cur.line, ch: cur.ch}
326 326
             );
327  
-            event.stopPropagation();
328  
-            event.preventDefault();
  327
+            if(event != null){
  328
+                event.stopPropagation();
  329
+                event.preventDefault();
  330
+            }
329 331
             close();
330 332
             setTimeout(function(){that.code_mirror.focus();}, 50);
331 333
         };
332 334
 
333 335
         // insert the curent highlited selection and exit
334 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 @@ var IPython = (function (IPython) {
340 342
         // matches, update the pseuso typing field. autopick insert match if
341 343
         // only one left, in no matches (anymore) dismiss itself by pasting
342 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 347
             // If autopick an only one match, past.
346 348
             // Used to 'pick' when pressing tab
347 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 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 362
             //clear the previous completion if any
353 363
             complete.children().children().remove();
@@ -381,7 +391,7 @@ var IPython = (function (IPython) {
381 391
         // the same letter and complete if necessary
382 392
         fastForward = sharedStart(matches)
383 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 395
         filterd=matches;
386 396
         // Give focus to select, and make it filter the match as the user type
387 397
         // by filtering the previous matches. Called by .keypress and .keydown
@@ -407,8 +417,8 @@ var IPython = (function (IPython) {
407 417
                 // but we want the default action.
408 418
                 event.stopPropagation();
409 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)){
411  
-                if((code != key.backspace) && (code != key.tab) && press)
  420
+            } else if ( (code==key.backspace)||(code==key.tab && down) || press || key.isCompSymbol(code)){
  421
+                if( key.isCompSymbol(code) && press)
412 422
                 {
413 423
                     var newchar = String.fromCharCode(code);
414 424
                     typed_characters=typed_characters+newchar;
@@ -419,22 +429,22 @@ var IPython = (function (IPython) {
419 429
                     autopick=true;
420 430
                     event.stopPropagation();
421 431
                     event.preventDefault();
422  
-                } else if (code == key.backspace) {
  432
+                } else if (code == key.backspace && down) {
423 433
                     // cancel if user have erase everything, otherwise decrease
424 434
                     // what we filter with
425 435
                     if (typed_characters.length <= 0)
426 436
                     {
427  
-                        insert(matched_text)
  437
+                        insert(matched_text,event)
428 438
                     }
429 439
                     typed_characters=typed_characters.substr(0,typed_characters.length-1);
430  
-                }
  440
+                }else{return}
431 441
                 re = new RegExp("^"+"\%?"+matched_text+typed_characters,"");
432 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 444
             } else if(down){ // abort only on .keydown
435 445
                 // abort with what the user have pressed until now
436 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 450
         select.keydown(function (event) {
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.