diff --git a/src/htmlContent/search-results.html b/src/htmlContent/search-results.html index 7c5a671b9cf..a335cabbcbb 100644 --- a/src/htmlContent/search-results.html +++ b/src/htmlContent/search-results.html @@ -2,7 +2,8 @@ {{#searchList}} - + {{#replace}}{{/replace}} + {{{filename}}} diff --git a/src/search/SearchResultsView.js b/src/search/SearchResultsView.js index 75de81f266f..8b07a9065ba 100644 --- a/src/search/SearchResultsView.js +++ b/src/search/SearchResultsView.js @@ -237,6 +237,45 @@ define(function (require, exports, module) { } }); + function updateHeaderCheckbox($checkAll) { + var $allFileRows = self._panel.$panel.find(".file-section"), + $checkedFileRows = $allFileRows.filter(function (index) { + return $(this).find(".check-one-file").is(":checked"); + }); + if ($checkedFileRows.length === $allFileRows.length) { + $checkAll.prop("checked", true); + } + } + + function updateFileAndHeaderCheckboxes($clickedRow, isChecked) { + var $firstMatch = ($clickedRow.data("item-index") === 0) ? $clickedRow : + $clickedRow.prevUntil(".file-section").last(), + $fileRow = $firstMatch.prev(), + $siblingRows = $fileRow.nextUntil(".file-section"), + $fileCheckbox = $fileRow.find(".check-one-file"), + $checkAll = self._panel.$panel.find(".check-all"); + + if (isChecked) { + if (!$fileCheckbox.is(":checked")) { + var $checkedSibilings = $siblingRows.filter(function (index) { + return $(this).find(".check-one").is(":checked"); + }); + if ($checkedSibilings.length === $siblingRows.length) { + $fileCheckbox.prop("checked", true); + if (!$checkAll.is(":checked")) { + updateHeaderCheckbox($checkAll); + } + } + } + } else { + if ($checkAll.is(":checked")) { + $checkAll.prop("checked", false); + } + if ($fileCheckbox.is(":checked")) { + $fileCheckbox.prop("checked", false); + } + } + } // Add the Click handlers for replace functionality if required if (this._model.isReplace) { @@ -249,18 +288,38 @@ define(function (require, exports, module) { }); }); self._$table.find(".check-one").prop("checked", isChecked); + self._$table.find(".check-one-file").prop("checked", isChecked); self._allChecked = isChecked; }) + .on("click.searchResults", ".check-one-file", function (e) { + var isChecked = $(this).is(":checked"), + $row = $(e.target).closest("tr"), + item = self._searchList[$row.data("file-index")], + $matchRows = $row.nextUntil(".file-section"), + $checkAll = self._panel.$panel.find(".check-all"); + + if (item) { + self._model.results[item.fullPath].matches.forEach(function (match) { + match.isChecked = isChecked; + }); + } + $matchRows.find(".check-one").prop("checked", isChecked); + if (!isChecked) { + if ($checkAll.is(":checked")) { + $checkAll.prop("checked", false); + } + } else if (!$checkAll.is(":checked")) { + updateHeaderCheckbox($checkAll); + } + e.stopPropagation(); + }) .on("click.searchResults", ".check-one", function (e) { var $row = $(e.target).closest("tr"), item = self._searchList[$row.data("file-index")], - match = self._model.results[item.fullPath].matches[$row.data("match-index")], - $checkAll = self._panel.$panel.find(".check-all"); + match = self._model.results[item.fullPath].matches[$row.data("match-index")]; match.isChecked = $(this).is(":checked"); - if (!match.isChecked && $checkAll.is(":checked")) { - $checkAll.prop("checked", false); - } + updateFileAndHeaderCheckboxes($row, match.isChecked); e.stopPropagation(); }) .on("click.searchResults", ".replace-checked", function (e) { @@ -318,12 +377,13 @@ define(function (require, exports, module) { */ SearchResultsView.prototype._render = function () { var searchItems, match, i, item, multiLine, - count = this._model.countFilesMatches(), - searchFiles = this._model.getSortedFiles(this._initialFilePath), - lastIndex = this._getLastIndex(count.matches), - matchesCounter = 0, - showMatches = false, - self = this; + count = this._model.countFilesMatches(), + searchFiles = this._model.getSortedFiles(this._initialFilePath), + lastIndex = this._getLastIndex(count.matches), + matchesCounter = 0, + showMatches = false, + allInFileChecked = true, + self = this; this._showSummary(); this._searchList = []; @@ -361,6 +421,7 @@ define(function (require, exports, module) { // Add a row for each match in the file searchItems = []; + allInFileChecked = true; // Add matches until we get to the last match of this item, or filling the page while (i < item.matches.length && matchesCounter < lastIndex) { match = item.matches[i]; @@ -378,6 +439,9 @@ define(function (require, exports, module) { end: match.end, isChecked: match.isChecked }); + if (!match.isChecked) { + allInFileChecked = false; + } matchesCounter++; i++; } @@ -396,6 +460,7 @@ define(function (require, exports, module) { fileIndex: self._searchList.length, filename: displayFileName, fullPath: fullPath, + isChecked: allInFileChecked, items: searchItems }); } diff --git a/src/styles/brackets.less b/src/styles/brackets.less index 7337af5b76f..fe0faaa3af0 100644 --- a/src/styles/brackets.less +++ b/src/styles/brackets.less @@ -443,8 +443,8 @@ a, img { vertical-align: baseline; } - .file-section > td { - padding-left: 5px; + .file-section > .checkbox-column { + width: 15px; } .line-number {