Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Issue 3660: Mouse wheel should scroll the completion popup

  • Loading branch information...
commit ab6f202e5ab95b10b8e6e48d55effaa09e3d608f 1 parent 3fb6d30
Simon Lindholm authored May 24, 2012
37  extension/content/firebug/console/autoCompleter.js
@@ -247,16 +247,20 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
247 247
     };
248 248
 
249 249
     /**
250  
-     * Go backward or forward one step in the list of completions.
251  
-     * dir is the relative movement in the list; -1 means backward and 1 forward.
  250
+     * Go backward or forward by some number of steps in the list of completions.
  251
+     * dir is the relative movement in the list (negative for backwards movement).
252 252
      */
253 253
     this.cycle = function(dir)
254 254
     {
255  
-        this.completions.index += dir;
256  
-        if (this.completions.index >= this.completions.list.length)
257  
-            this.completions.index = 0;
258  
-        else if (this.completions.index < 0)
259  
-            this.completions.index = this.completions.list.length - 1;
  255
+        var ind = this.completions.index;
  256
+        if (ind === this.completions.list.length - 1 && dir > 0)
  257
+            ind = 0;
  258
+        else if (ind === 0 && dir < 0)
  259
+            ind = this.completions.list.length - 1;
  260
+        else
  261
+            ind += dir;
  262
+        ind = Math.max(Math.min(ind, this.completions.list.length - 1), 0);
  263
+        this.completions.index = ind;
260 264
         this.showCompletions(true);
261 265
     };
262 266
 
@@ -478,11 +482,8 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
478 482
         if (!this.isPopupOpen())
479 483
         {
480 484
             // When no popup is open, cycle by a fixed amount and stop at edges.
481  
-            selIndex += dir * 15;
482  
-            selIndex = Math.max(selIndex, 0);
483  
-            selIndex = Math.min(selIndex, list.length-1);
484  
-            this.completions.index = selIndex;
485  
-            this.showCompletions(true);
  485
+            if (selIndex !== (dir === -1 ? 0 : list.length-1))
  486
+                this.cycle(dir * 15);
486 487
             return;
487 488
         }
488 489
 
@@ -666,6 +667,15 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
666 667
         this.completionBox.value = this.getCompletionBoxValue();
667 668
     };
668 669
 
  670
+    this.popupScroll = function(event)
  671
+    {
  672
+        if (event.axis !== event.VERTICAL_AXIS)
  673
+            return;
  674
+        if (!this.getCompletionPopupElementFromEvent(event))
  675
+            return;
  676
+        this.cycle(event.detail);
  677
+    };
  678
+
669 679
     this.popupClick = function(event)
670 680
     {
671 681
         var el = this.getCompletionPopupElementFromEvent(event);
@@ -677,6 +687,7 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
677 687
     };
678 688
 
679 689
     this.popupMousedown = Obj.bind(this.popupMousedown, this);
  690
+    this.popupScroll = Obj.bind(this.popupScroll, this);
680 691
     this.popupClick = Obj.bind(this.popupClick, this);
681 692
 
682 693
     /**
@@ -689,6 +700,7 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
689 700
         if (this.completionPopup)
690 701
         {
691 702
             Events.removeEventListener(this.completionPopup, "mousedown", this.popupMousedown, true);
  703
+            Events.removeEventListener(this.completionPopup, "DOMMouseScroll", this.popupScroll, true);
692 704
             Events.removeEventListener(this.completionPopup, "click", this.popupClick, true);
693 705
         }
694 706
     };
@@ -696,6 +708,7 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
696 708
     if (this.completionPopup)
697 709
     {
698 710
         Events.addEventListener(this.completionPopup, "mousedown", this.popupMousedown, true);
  711
+        Events.addEventListener(this.completionPopup, "DOMMouseScroll", this.popupScroll, true);
699 712
         Events.addEventListener(this.completionPopup, "click", this.popupClick, true);
700 713
     }
701 714
 };

0 notes on commit ab6f202

Please sign in to comment.
Something went wrong with that request. Please try again.