From c78541cd7fcb5c70eeabc0fe3ca558e87b4c7274 Mon Sep 17 00:00:00 2001 From: Jackson Cleary Date: Thu, 2 Oct 2014 00:22:30 +1000 Subject: [PATCH] Issue #8557- fixed to show correct result count --- src/search/FindInFiles.js | 4 +++- src/search/SearchModel.js | 15 +++++++++++++-- src/search/SearchResultsView.js | 11 ++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/search/FindInFiles.js b/src/search/FindInFiles.js index 7cdb28f894c..f12a7c8c301 100644 --- a/src/search/FindInFiles.js +++ b/src/search/FindInFiles.js @@ -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; } diff --git a/src/search/SearchModel.js b/src/search/SearchModel.js index bd35ed14bde..617503bac20 100644 --- a/src/search/SearchModel.js +++ b/src/search/SearchModel.js @@ -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; @@ -112,6 +115,7 @@ define(function (require, exports, module) { this.scope = null; this.numMatches = 0; this.foundMaximum = false; + this.exceedsMaximum = false; this.fireChanged(); }; @@ -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; + } } }; diff --git a/src/search/SearchResultsView.js b/src/search/SearchResultsView.js index eb306577be4..4c0438f3ecc 100644 --- a/src/search/SearchResultsView.js +++ b/src/search/SearchResultsView.js @@ -28,7 +28,7 @@ */ define(function (require, exports, module) { "use strict"; - + var CommandManager = require("command/CommandManager"), Commands = require("command/Commands"), DocumentManager = require("document/DocumentManager"), @@ -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. @@ -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