Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1844 from adobe/randy/issue-1829
Browse files Browse the repository at this point in the history
Find In Files: stop searching a file once we reach max hits
  • Loading branch information
gruehle committed Oct 16, 2012
2 parents 74c3371 + 6493f0e commit 9712991
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ define({
"FIND_IN_FILES_FILES" : "files",
"FIND_IN_FILES_MATCH" : "match",
"FIND_IN_FILES_MATCHES" : "matches",
"FIND_IN_FILES_MORE_THAN" : "More than ",
"FIND_IN_FILES_MAX" : " (showing the first {0} matches)",
"FIND_IN_FILES_FILE_PATH" : "File: <b>{0}</b>",
"FIND_IN_FILES_LINE" : "line:&nbsp;{0}",
Expand Down
20 changes: 18 additions & 2 deletions src/search/FindInFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ define(function (require, exports, module) {

var searchResults = [];

var FIND_IN_FILES_MAX = 100;
var FIND_IN_FILES_MAX = 100,
maxHitsFoundInFile = false;

var PREFERENCES_CLIENT_ID = module.id,
defaultPrefs = { height: 200 };
Expand Down Expand Up @@ -172,6 +173,14 @@ define(function (require, exports, module) {
end: {line: lineNum, ch: ch + matchLength},
line: line
});

// We have the max hits in just this 1 file. Stop searching this file.
// This fixed issue #1829 where code hangs on too many hits.
if (matches.length >= FIND_IN_FILES_MAX) {
queryExpr.lastIndex = 0;
maxHitsFoundInFile = true;
break;
}
}

return matches;
Expand All @@ -191,9 +200,15 @@ define(function (require, exports, module) {
});

// Show result summary in header
var numMatchesStr = "";
if (maxHitsFoundInFile) {
numMatchesStr = Strings.FIND_IN_FILES_MORE_THAN;
}
numMatchesStr += String(numMatches);

var summary = StringUtils.format(
Strings.FIND_IN_FILES_TITLE,
numMatches,
numMatchesStr,
(numMatches > 1) ? Strings.FIND_IN_FILES_MATCHES : Strings.FIND_IN_FILES_MATCH,
searchResults.length,
(searchResults.length > 1 ? Strings.FIND_IN_FILES_FILES : Strings.FIND_IN_FILES_FILE),
Expand Down Expand Up @@ -307,6 +322,7 @@ define(function (require, exports, module) {
var initialString = currentEditor && currentEditor.getSelectedText();

searchResults = [];
maxHitsFoundInFile = false;

dialog.showDialog(initialString)
.done(function (query) {
Expand Down

0 comments on commit 9712991

Please sign in to comment.