Bug 876277 - Clicking on global search results lines (not matches) was broken after 877686, fix it, r=past
authorVictor Porof <vporof@mozilla.com>
Fri, 13 Sep 2013 16:23:15 +0300
changeset 147075 ecdd787c9eff242c0e438fea2e3b8dd1532755c5
parent 147074 9cc32e5a67ea6587d53724743a7398b4e215a7ba
child 147076 1757ae16bf8a50e52b588685dc9068ffadea60e7
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerspast
bugs876277, 877686
milestone26.0a1
Bug 876277 - Clicking on global search results lines (not matches) was broken after 877686, fix it, r=past
browser/devtools/debugger/debugger-panes.js
browser/devtools/shared/widgets/ViewHelpers.jsm
--- a/browser/devtools/debugger/debugger-panes.js
+++ b/browser/devtools/debugger/debugger-panes.js
@@ -2126,17 +2126,17 @@ LineResults.prototype.__iterator__ = fun
  *
  * @param nsIDOMNode aElement
  *        The element used to identify the item.
  * @return object
  *         The matched item, or null if nothing is found.
  */
 SourceResults.getItemForElement =
 LineResults.getItemForElement = function(aElement) {
-  return WidgetMethods.getItemForElement.call(this, aElement);
+  return WidgetMethods.getItemForElement.call(this, aElement, { noSiblings: true });
 };
 
 /**
  * Gets the element associated with a particular item at a specified index.
  *
  * @param number aIndex
  *        The index used to identify the item.
  * @return nsIDOMNode
--- a/browser/devtools/shared/widgets/ViewHelpers.jsm
+++ b/browser/devtools/shared/widgets/ViewHelpers.jsm
@@ -1232,25 +1232,33 @@ this.WidgetMethods = {
     return this._itemsByValue.get(aValue);
   },
 
   /**
    * Gets the item in the container associated with the specified element.
    *
    * @param nsIDOMNode aElement
    *        The element used to identify the item.
+   * @param object aFlags [optional]
+   *        Additional options for showing the source. Supported options:
+   *          - noSiblings: if siblings shouldn't be taken into consideration
+   *                        when searching for the associated item.
    * @return Item
    *         The matched item, or null if nothing is found.
    */
-  getItemForElement: function(aElement) {
+  getItemForElement: function(aElement, aFlags = {}) {
     while (aElement) {
-      let item =
-        this._itemsByElement.get(aElement) ||
-        this._itemsByElement.get(aElement.nextElementSibling) ||
-        this._itemsByElement.get(aElement.previousElementSibling);
+      let item = this._itemsByElement.get(aElement);
+
+      // Also search the siblings if allowed.
+      if (!aFlags.noSiblings) {
+        item = item ||
+          this._itemsByElement.get(aElement.nextElementSibling) ||
+          this._itemsByElement.get(aElement.previousElementSibling);
+      }
       if (item) {
         return item;
       }
       aElement = aElement.parentNode;
     }
     return null;
   },