From c78541cd7fcb5c70eeabc0fe3ca558e87b4c7274 Mon Sep 17 00:00:00 2001 From: Jackson Cleary Date: Thu, 2 Oct 2014 00:22:30 +1000 Subject: [PATCH 1/5] 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 From 5eaaee8e966e825c010ddd33ea836825e381bac2 Mon Sep 17 00:00:00 2001 From: Jackson Cleary Date: Thu, 2 Oct 2014 00:32:44 +1000 Subject: [PATCH 2/5] Removed unused reference to SearchModel --- src/search/SearchResultsView.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/search/SearchResultsView.js b/src/search/SearchResultsView.js index 4c0438f3ecc..c938a5be67e 100644 --- a/src/search/SearchResultsView.js +++ b/src/search/SearchResultsView.js @@ -38,7 +38,6 @@ 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"), From 35f7280548ec34a218ccf06c4d2090c0cbdfb3e1 Mon Sep 17 00:00:00 2001 From: Jackson Cleary Date: Sat, 4 Oct 2014 09:44:02 +1000 Subject: [PATCH 3/5] Add comment back to clear() function --- src/search/SearchModel.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/search/SearchModel.js b/src/search/SearchModel.js index 617503bac20..ba9b097b98d 100644 --- a/src/search/SearchModel.js +++ b/src/search/SearchModel.js @@ -106,6 +106,9 @@ define(function (require, exports, module) { */ SearchModel.prototype.exceedsMaximum = false; + /** + * Clears out the model to an empty state. + */ SearchModel.prototype.clear = function () { this.results = {}; this.queryInfo = null; From d63a1248ab8ab9f43017b454b79db7004a3aaaf1 Mon Sep 17 00:00:00 2001 From: Jackson Cleary Date: Sat, 4 Oct 2014 09:57:30 +1000 Subject: [PATCH 4/5] Changed -- to conform to JSLint --- src/search/SearchModel.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/search/SearchModel.js b/src/search/SearchModel.js index ba9b097b98d..dfb008038ac 100644 --- a/src/search/SearchModel.js +++ b/src/search/SearchModel.js @@ -168,9 +168,9 @@ define(function (require, exports, module) { // 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.numMatches -= 1; this.exceedsMaximum = true; - } + } } }; From 0c83a927f850abced2c12a1d896530bfbeb89b02 Mon Sep 17 00:00:00 2001 From: Jackson Cleary Date: Wed, 8 Oct 2014 19:06:35 +1100 Subject: [PATCH 5/5] Conform code to conventions --- src/search/FindInFiles.js | 4 ++-- src/search/SearchModel.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/search/FindInFiles.js b/src/search/FindInFiles.js index f12a7c8c301..62e608e787b 100644 --- a/src/search/FindInFiles.js +++ b/src/search/FindInFiles.js @@ -127,8 +127,8 @@ 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. - // ** 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 ** + // 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 dfb008038ac..dac66a2f17e 100644 --- a/src/search/SearchModel.js +++ b/src/search/SearchModel.js @@ -168,7 +168,7 @@ define(function (require, exports, module) { // 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 -= 1; + this.numMatches--; this.exceedsMaximum = true; } }