Index: Source/devtools/front_end/source_frame/SourceFrame.js |
diff --git a/Source/devtools/front_end/source_frame/SourceFrame.js b/Source/devtools/front_end/source_frame/SourceFrame.js |
index 6c5756844ef18f95c827dbd2d4d1b11b341c479e..c53a16f2911e55d8564ea91d40b9ea6a7d1f5368 100644 |
--- a/Source/devtools/front_end/source_frame/SourceFrame.js |
+++ b/Source/devtools/front_end/source_frame/SourceFrame.js |
@@ -82,9 +82,9 @@ WebInspector.SourceFrame.createSearchRegex = function(query, modifiers) |
// Silent catch. |
} |
- // Otherwise just do case-insensitive search. |
+ // Otherwise just do a plain text search. |
if (!regex) |
- regex = createPlainTextSearchRegex(query, "i" + modifiers); |
+ regex = createPlainTextSearchRegex(query, modifiers); |
return regex; |
} |
@@ -397,25 +397,26 @@ WebInspector.SourceFrame.prototype = { |
}, |
/** |
- * @param {string} query |
+ * @param {!WebInspector.SearchableView.SearchConfig} searchConfig |
* @param {boolean} shouldJump |
* @param {boolean} jumpBackwards |
* @param {function(!WebInspector.View, number)} callback |
* @param {function(number)} currentMatchChangedCallback |
* @param {function()} searchResultsChangedCallback |
*/ |
- performSearch: function(query, shouldJump, jumpBackwards, callback, currentMatchChangedCallback, searchResultsChangedCallback) |
+ performSearch: function(searchConfig, shouldJump, jumpBackwards, callback, currentMatchChangedCallback, searchResultsChangedCallback) |
{ |
/** |
- * @param {string} query |
* @this {WebInspector.SourceFrame} |
*/ |
- function doFindSearchMatches(query) |
+ function doFindSearchMatches() |
lushnikov
2014/10/20 13:09:19
In order to simplify reading, can we have this met
|
{ |
this._currentSearchResultIndex = -1; |
this._searchResults = []; |
- var regex = WebInspector.SourceFrame.createSearchRegex(query); |
+ var modifiers = searchConfig.caseSensitive ? "" : "i"; |
+ var query = searchConfig.isRegex ? "/" + searchConfig.query + "/" : searchConfig.query; |
+ var regex = WebInspector.SourceFrame.createSearchRegex(query, modifiers); |
this._searchRegex = regex; |
this._searchResults = this._collectRegexMatches(regex); |
if (!this._searchResults.length) |
@@ -433,9 +434,9 @@ WebInspector.SourceFrame.prototype = { |
this._currentSearchMatchChangedCallback = currentMatchChangedCallback; |
this._searchResultsChangedCallback = searchResultsChangedCallback; |
if (this.loaded) |
- doFindSearchMatches.call(this, query); |
+ doFindSearchMatches.call(this); |
else |
- this._delayedFindSearchMatches = doFindSearchMatches.bind(this, query); |
+ this._delayedFindSearchMatches = doFindSearchMatches.bind(this); |
this._ensureContentLoaded(); |
}, |
@@ -547,29 +548,32 @@ WebInspector.SourceFrame.prototype = { |
}, |
/** |
- * @param {string} text |
+ * @param {string} replacement |
*/ |
- replaceSelectionWith: function(text) |
+ replaceSelectionWith: function(replacement) |
{ |
var range = this._searchResults[this._currentSearchResultIndex]; |
if (!range) |
return; |
this._textEditor.highlightSearchResults(this._searchRegex, null); |
- var newRange = this._textEditor.editRange(range, text); |
+ var newRange = this._textEditor.editRange(range, replacement); |
this._textEditor.setSelection(newRange.collapseToEnd()); |
}, |
/** |
- * @param {string} query |
+ * @param {!WebInspector.SearchableView.SearchConfig} searchConfig |
* @param {string} replacement |
*/ |
- replaceAllWith: function(query, replacement) |
+ replaceAllWith: function(searchConfig, replacement) |
{ |
this._resetCurrentSearchResultIndex(); |
var text = this._textEditor.text(); |
var range = this._textEditor.range(); |
- var regex = WebInspector.SourceFrame.createSearchRegex(query, "g"); |
+ |
+ var modifiers = searchConfig.caseSensitive ? "" : "i"; |
+ var query = searchConfig.isRegex ? "/" + searchConfig.query + "/" : searchConfig.query; |
+ var regex = WebInspector.SourceFrame.createSearchRegex(query, "g" + modifiers); |
if (regex.__fromRegExpQuery) |
text = text.replace(regex, replacement); |
else |
@@ -604,10 +608,11 @@ WebInspector.SourceFrame.prototype = { |
do { |
var match = regexObject.exec(line); |
if (match) { |
+ var matchEndIndex = match.index + Math.max(match[0].length, 1); |
if (match[0].length) |
- ranges.push(new WebInspector.TextRange(i, offset + match.index, i, offset + match.index + match[0].length)); |
- offset += match.index + 1; |
- line = line.substring(match.index + 1); |
+ ranges.push(new WebInspector.TextRange(i, offset + match.index, i, offset + matchEndIndex)); |
+ offset += matchEndIndex; |
+ line = line.substring(matchEndIndex); |
} |
} while (match && line); |
} |