Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Expand / Collapse All for "Find In Files" result. #5757

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ define({
"FIND_IN_FILES_MORE_THAN" : "Over ",
"FIND_IN_FILES_PAGING" : "{0}—{1}",
"FIND_IN_FILES_FILE_PATH" : "<span class='dialog-filename'>{0}</span> {2} <span class='dialog-path'>{1}</span>", // We shoudl use normal dashes on Windows instead of em dash eventually
"FIND_IN_FILES_EXPAND_COLLAPSE" : "Ctrl/Cmd click to expand/collapse all",
"ERROR_FETCHING_UPDATE_INFO_TITLE" : "Error getting update info",
"ERROR_FETCHING_UPDATE_INFO_MSG" : "There was a problem getting the latest update information from the server. Please make sure you are connected to the internet and try again.",

Expand Down
31 changes: 25 additions & 6 deletions src/search/FindInFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,30 @@ define(function (require, exports, module) {

// This is a file title row, expand/collapse on click
if ($row.hasClass("file-section")) {
// Clicking the file section header collapses/expands result rows for that file
$row.nextUntil(".file-section").toggle();

var $triangle = $(".disclosure-triangle", $row);
$triangle.toggleClass("expanded").toggleClass("collapsed");

searchResults[fullPath].collapsed = !searchResults[fullPath].collapsed;
if (e.metaKey || e.ctrlKey) { //Expand all / Collapse all
var $titleRows = $(e.target).closest("table").find(".file-section"),
collapsed = !searchResults[fullPath].collapsed;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this variable was declared before the if, then we could also use it in line 456.


$titleRows.each(function () {
searchItem = searchList[$(this).data("file")];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will look nicer to do here var fullPath = searchList[$(this).data("file")].fullPath

fullPath = searchItem.fullPath;

if (searchResults[fullPath].collapsed !== collapsed) {
$(this).nextUntil(".file-section").toggle();
$(this).find(".disclosure-triangle").toggleClass("expanded").toggleClass("collapsed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 lines are almost the sames as lines (454-455), only the element changes. So I was thinking that maybe we could have a function: _collapseFileResults($row, collapse: boolean) that could collapse, or uncollapse the results depending on the boolean parameter. Not sure if we should also change the collapse value of the results object in this function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should change the internal state too, so the function can be _collapseFileResults($row, collapse, fullPath).

}
});

_.forEach(searchResults, function (item) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a comment here to mention that this is required to collapse/uncollapse all the files and not just the ones in the current page.

item.collapsed = collapsed;
});
} else {
// Clicking the file section header collapses/expands result rows for that file
$row.nextUntil(".file-section").toggle();
$row.find(".disclosure-triangle").toggleClass("expanded").toggleClass("collapsed");
searchResults[fullPath].collapsed = !searchResults[fullPath].collapsed;
}

// This is a file row, show the result on click
} else {
Expand Down Expand Up @@ -467,6 +484,8 @@ define(function (require, exports, module) {
}
});

$searchContent.find(".disclosure-triangle").attr("title", Strings.FIND_IN_FILES_EXPAND_COLLAPSE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added to the html template.


if ($selectedRow) {
$selectedRow.removeClass("selected");
$selectedRow = null;
Expand Down