Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/htmlContent/search-results.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<tbody>
{{#searchList}}
<tr class="file-section" data-file-index="{{fileIndex}}">
<td colspan="{{#replace}}3{{/replace}}{{^replace}}2{{/replace}}">
{{#replace}}<td class="checkbox-column"><input type="checkbox" class="check-one-file" {{#isChecked}}checked="true"{{/isChecked}} /></td>{{/replace}}
<td colspan="2">
<span class="disclosure-triangle expanded" title="{{Strings.FIND_IN_FILES_EXPAND_COLLAPSE}}"></span>
{{{filename}}}
</td>
Expand Down
87 changes: 76 additions & 11 deletions src/search/SearchResultsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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];
Expand All @@ -378,6 +439,9 @@ define(function (require, exports, module) {
end: match.end,
isChecked: match.isChecked
});
if (!match.isChecked) {
allInFileChecked = false;
}
matchesCounter++;
i++;
}
Expand All @@ -396,6 +460,7 @@ define(function (require, exports, module) {
fileIndex: self._searchList.length,
filename: displayFileName,
fullPath: fullPath,
isChecked: allInFileChecked,
items: searchItems
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/styles/brackets.less
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ a, img {
vertical-align: baseline;
}

.file-section > td {
padding-left: 5px;
.file-section > .checkbox-column {
width: 15px;
}

.line-number {
Expand Down