Bug 1335905 - Fixed a bug in searching text nodes draft
authormanotejmeka <manotejmeka@gmail.com>
Sun, 19 Feb 2017 19:03:21 -0500
changeset 486800 8bff074397c6024240ec1b05c4cd557384eed3d4
parent 486799 5505de47dfe2b23248bebb300785b7b91f7888eb
child 487107 c67adedb84af5966ef658307f34caf82b2f12050
push id46062
push userbmo:manotejmeka@gmail.com
push dateMon, 20 Feb 2017 00:32:40 +0000
bugs1335905
milestone54.0a1
Bug 1335905 - Fixed a bug in searching text nodes MozReview-Commit-ID: BcT77giA7Ts
browser/components/preferences/in-content/SearchEach.js
--- a/browser/components/preferences/in-content/SearchEach.js
+++ b/browser/components/preferences/in-content/SearchEach.js
@@ -107,16 +107,17 @@ function stringMatchesFilters(str, filte
     return !filterStrings.some(function(f) {
         return searchStr.indexOf(f) == -1;
     });
 }
 
 function nodeRecursion(nodeObject, searchPhrase, findSelection) {
     let foundIn = false;
     if (nodeObject.childElementCount == 0) {
+
         let leafTextNodes, otherTextNodes = [];
         let listOfWords = searchPhrase.trim().split(); //  List of words to search from
 
         //  Searching in the Text Nodes
         if (nodeObject) {
             leafTextNodes = textNodesUnder(nodeObject);
         }
         if (nodeObject.boxObject) {
@@ -149,16 +150,17 @@ function nodeRecursion(nodeObject, searc
         });
 
         listOfWords.forEach(function(word) {
             let boolAns = multiSearch(otherTextNodes, nodeSizes, allNodeText, word, findSelection);
             // searchWord(node,node.textContent,word,findSelection)
             foundIn = foundIn || boolAns;
         });
 
+        
         //  Searching in the buttons
         listOfWords.forEach(function(word) {
             let boolAns = getLabelAttribute(nodeObject, word);
             foundIn = foundIn || boolAns;
             // if (getLabelAttribute(nodeObject,word)){
             //     console.log(nodeObject)
             //     foundIn = true
             // }
@@ -168,18 +170,19 @@ function nodeRecursion(nodeObject, searc
         listOfWords.forEach(function(word) {
             let boolAns = getValueAttribute(nodeObject, word, findSelection);
             foundIn = foundIn || boolAns;
             // if (getLabelAttribute(nodeObject,word)){
             //     console.log(nodeObject)
             //     foundIn = true
             // }
         });
+        
     }
-    for (let i = 0; i < nodeObject.childElementCount; i++) {
+    for (let i = 0; i < nodeObject.childNodes.length; i++) {
         let boolAns = nodeRecursion(nodeObject.childNodes[i], searchPhrase, findSelection);
         foundIn = foundIn || boolAns;
         // foundIn = foundIn || nodeRecursion(nodeObject.childNodes[i], searchPhrase, findSelection)
     }
     return foundIn;
 }
 
 // http:// stackoverflow.com/questions/10730309/find-all-text-nodes-in-html-page
@@ -195,16 +198,20 @@ function textNodesUnder(node) {
 function searchWord(textNode, textSearch, word, findSelection) {
     let regExp = new RegExp(word, "gi");
     let result, indices = [];
 
     while ((result = regExp.exec(textSearch))) {
         indices.push(result.index);
     }
 
+    if (indices.length > 0 ){
+        console.log("Search Word",textNode, textSearch)
+    }
+
     //  Add each found word to range
     for (let i = 0; i < indices.length; i++) {
         let range = document.createRange();
         range.setStart(textNode, indices[i]);
         range.setEnd(textNode, (indices[i] + word.length) );
         findSelection.addRange(range); //  Add each range to be highlighted
     }
     return indices.length > 0;
@@ -213,23 +220,26 @@ function searchWord(textNode, textSearch
 function multiSearch(textNodes, nodeSizes, textSearch, word, findSelection) {
     let regExp = new RegExp(word, "gi");
     let result, indices = [];
 
     while ((result = regExp.exec(textSearch))) {
         indices.push(result.index);
     }
 
-    /* if (indices.length > 0){
-        console.log("Other words")
-        console.log(textNodes)
-        console.log(nodeSizes)
-        console.log(textSearch)
-        console.log("End other words")
-    } */
+    /*
+    if (indices.length > 0){
+        console.log("Multi Searcb",textNodes,textSearch)
+        //console.log("Other words")
+        //console.log(textNodes)
+        //console.log(nodeSizes)
+        //console.log(textSearch)
+        //console.log("End other words")
+    } 
+    */
     indices.forEach(function(startValue, startIndex) {
         let endValue = startValue + word.length;
         let startNode = null;
         let endNode = null;
         let nodeStartIndex = null;
 
         nodeSizes.forEach(function(lengthNodes, index) {
             if (!startNode && lengthNodes >= startValue) {