Bug 1335905 - Switch to indexOf instead of RegExp
MozReview-Commit-ID: 7yk8SeCrPAP
--- a/browser/components/preferences/in-content/findInPage.js
+++ b/browser/components/preferences/in-content/findInPage.js
@@ -110,26 +110,25 @@ var gSearchResultsPane = {
* Concatination of textNodes's text content
* Example:
* textNodes = [[This is ], [a], [n example]]
* nodeSizes = "This is an example"
* This is used when executing the regular expression
* @param String searchPhrase
* word or words to search for
* @returns boolean
- * Returns true when atleast one instance of search phrase is found, otherwise false
+ * Returns true when at least one instance of search phrase is found, otherwise false
*/
highlightMatches(textNodes, nodeSizes, textSearch, searchPhrase) {
- let regExp = new RegExp(searchPhrase.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"), "gi");
- let result, indices = [];
-
- while ((result = regExp.exec(textSearch))) {
- indices.push(result.index);
+ let indices = [];
+ let i=-1;
+ while((i=textSearch.indexOf(searchPhrase,i+1)) >= 0) {
+ indices.push(i);
}
-
+
// Looping through each spot the searchPhrase is found in the concatenated string
for (let startValue of indices) {
let endValue = startValue + searchPhrase.length;
let startNode = null;
let endNode = null;
let nodeStartIndex = null;
// Determining the start and end node to highlight from
@@ -182,17 +181,17 @@ var gSearchResultsPane = {
/**
* Shows or hides content according to search input
*
* @param String event
* to search for filted query in
*/
searchFunction(event) {
- let query = event.target.value.trim();
+ let query = event.target.value.trim().toLowerCase();
this.findSelection.removeAllRanges();
let srHeader = document.getElementById("header-searchResults");
if (query) {
// Showing the Search Results Tag
gotoPref("paneSearchResults");
@@ -256,17 +255,17 @@ var gSearchResultsPane = {
* Returns true when found in at least one childNode, false otherwise
*/
searchWithinNode(nodeObject, searchPhrase) {
let matchesFound = false;
if (nodeObject.childElementCount == 0) {
let simpleTextNodes = this.textNodeDescendants(nodeObject);
for (let node of simpleTextNodes) {
- let result = this.highlightMatches([node], [node.length], node.textContent, searchPhrase);
+ let result = this.highlightMatches([node], [node.length], node.textContent.toLowerCase(), searchPhrase);
matchesFound = matchesFound || result;
}
// Collecting data from boxObject
let nodeSizes = [];
let allNodeText = "";
let runningSize = 0;
let labelResult = false;
@@ -275,17 +274,17 @@ var gSearchResultsPane = {
for (let node of accessKeyTextNodes) {
runningSize += node.textContent.length;
allNodeText += node.textContent;
nodeSizes.push(runningSize);
}
// Access key are presented
- let complexTextNodesResult = this.highlightMatches(accessKeyTextNodes, nodeSizes, allNodeText, searchPhrase);
+ let complexTextNodesResult = this.highlightMatches(accessKeyTextNodes, nodeSizes, allNodeText.toLowerCase(), searchPhrase);
// Searching some elements, such as xul:button, have a 'label' attribute that contains the user-visible text.
if (nodeObject.getAttribute("label")) {
labelResult = this.stringMatchesFilters(nodeObject.getAttribute("label"), searchPhrase);
}
// Searching some elements, such as xul:label, store their user-visible text in a "value" attribute.
if (nodeObject.getAttribute("value")) {