Skip to content

Commit

Permalink
Issue adobe#8557- fixed to show correct result count
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonweekes committed Oct 1, 2014
1 parent 02ffd66 commit c78541c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/search/FindInFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ define(function (require, exports, module) {

// 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 >= SearchModel.MAX_TOTAL_RESULTS) {
// ** Adds one over MAX_TOTAL_RESULTS in order to know if the search has exceeded
// or is equal to MAX_TOTAL_RESULTS. Additional result removed in SearchModel **
if (matches.length > SearchModel.MAX_TOTAL_RESULTS) {
queryExpr.lastIndex = 0;
break;
}
Expand Down
15 changes: 13 additions & 2 deletions src/search/SearchModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ define(function (require, exports, module) {
* @type {boolean}
*/
SearchModel.prototype.foundMaximum = false;

/**
* Clears out the model to an empty state.
* Whether or not we exceeded the maximum number of results in the search we did.
* @type {boolean}
*/
SearchModel.prototype.exceedsMaximum = false;

SearchModel.prototype.clear = function () {
this.results = {};
this.queryInfo = null;
Expand All @@ -112,6 +115,7 @@ define(function (require, exports, module) {
this.scope = null;
this.numMatches = 0;
this.foundMaximum = false;
this.exceedsMaximum = false;
this.fireChanged();
};

Expand Down Expand Up @@ -157,6 +161,13 @@ define(function (require, exports, module) {
this.numMatches += resultInfo.matches.length;
if (this.numMatches >= SearchModel.MAX_TOTAL_RESULTS) {
this.foundMaximum = true;

// Remove final result if there have been over MAX_TOTAL_RESULTS found
if (this.numMatches > SearchModel.MAX_TOTAL_RESULTS) {
this.results[fullpath].matches.pop();
this.numMatches--;
this.exceedsMaximum = true;
}
}
};

Expand Down
11 changes: 6 additions & 5 deletions src/search/SearchResultsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
define(function (require, exports, module) {
"use strict";

var CommandManager = require("command/CommandManager"),
Commands = require("command/Commands"),
DocumentManager = require("document/DocumentManager"),
Expand All @@ -38,15 +38,16 @@ define(function (require, exports, module) {
FileUtils = require("file/FileUtils"),
FindUtils = require("search/FindUtils"),
WorkspaceManager = require("view/WorkspaceManager"),
SearchModel = require("search/SearchModel").SearchModel,
StringUtils = require("utils/StringUtils"),
Strings = require("strings"),
_ = require("thirdparty/lodash"),

searchPanelTemplate = require("text!htmlContent/search-panel.html"),
searchResultsTemplate = require("text!htmlContent/search-results.html"),
searchSummaryTemplate = require("text!htmlContent/search-summary.html");


/**
* @const
* The maximum results to show per page.
Expand Down Expand Up @@ -348,7 +349,7 @@ define(function (require, exports, module) {
// This text contains some formatting, so all the strings are assumed to be already escaped
summary = StringUtils.format(
Strings.FIND_TITLE_SUMMARY,
this._model.foundMaximum ? Strings.FIND_IN_FILES_MORE_THAN : "",
this._model.exceedsMaximum ? Strings.FIND_IN_FILES_MORE_THAN : "",
String(count.matches),
(count.matches > 1) ? Strings.FIND_IN_FILES_MATCHES : Strings.FIND_IN_FILES_MATCH,
filesStr
Expand Down

0 comments on commit c78541c

Please sign in to comment.