Skip to content

Commit

Permalink
make fully collapsed state up to under Text Results or AI Results (
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamah authored Oct 3, 2024
1 parent 14d02fe commit 9e32d9e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
30 changes: 26 additions & 4 deletions src/vs/workbench/contrib/search/browser/searchActionsTopBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IViewsService } from '../../../services/views/common/viewsService.js';
import { searchClearIcon, searchCollapseAllIcon, searchExpandAllIcon, searchRefreshIcon, searchShowAsList, searchShowAsTree, searchStopIcon } from './searchIcons.js';
import * as Constants from '../common/constants.js';
import { ISearchHistoryService } from '../common/searchHistoryService.js';
import { FileMatch, FolderMatch, FolderMatchNoRoot, FolderMatchWorkspaceRoot, Match, SearchResult } from './searchModel.js';
import { FileMatch, FolderMatch, FolderMatchNoRoot, FolderMatchWorkspaceRoot, Match, SearchResult, TextSearchResult } from './searchModel.js';
import { VIEW_ID } from '../../../services/search/common/search.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
import { Action2, MenuId, registerAction2 } from '../../../../platform/actions/common/actions.js';
Expand Down Expand Up @@ -266,8 +266,16 @@ function collapseDeepestExpandedLevel(accessor: ServicesAccessor) {
let canCollapseFileMatchLevel = false;
let canCollapseFirstLevel = false;

do {
node = navigator.next();
} while (node instanceof TextSearchResult);
// go to the first non-TextSearchResult node

if (node instanceof FolderMatchWorkspaceRoot || searchView.isTreeLayoutViewVisible) {
while (node = navigator.next()) {
if (node instanceof TextSearchResult) {
continue;
}
if (node instanceof Match) {
canCollapseFileMatchLevel = true;
break;
Expand All @@ -277,13 +285,13 @@ function collapseDeepestExpandedLevel(accessor: ServicesAccessor) {

if (node instanceof FolderMatch) {
const compressionStartNode = viewer.getCompressedTreeNode(node)?.elements[0].element;
// Match elements should never be compressed, so !(compressionStartNode instanceof Match) should always be true here
nodeToTest = (compressionStartNode && !(compressionStartNode instanceof Match) && !(compressionStartNode instanceof SearchResult)) ? compressionStartNode : node;
// Match elements should never be compressed, so `!(compressionStartNode instanceof Match)` should always be true here. Same with `!(compressionStartNode instanceof TextSearchResult)`
nodeToTest = (compressionStartNode && !(compressionStartNode instanceof Match) && !(compressionStartNode instanceof TextSearchResult) && !(compressionStartNode instanceof SearchResult)) ? compressionStartNode : node;
}

const immediateParent = nodeToTest.parent();

if (!(immediateParent instanceof FolderMatchWorkspaceRoot || immediateParent instanceof FolderMatchNoRoot || immediateParent instanceof SearchResult)) {
if (!(immediateParent instanceof TextSearchResult || immediateParent instanceof FolderMatchWorkspaceRoot || immediateParent instanceof FolderMatchNoRoot || immediateParent instanceof SearchResult)) {
canCollapseFirstLevel = true;
}
}
Expand Down Expand Up @@ -320,6 +328,20 @@ function collapseDeepestExpandedLevel(accessor: ServicesAccessor) {
}
} while (node = navigator.next());
}
} else if (navigator.first() instanceof TextSearchResult) {
// if AI results are visible, just collapse everything under the TextSearchResult.
node = navigator.first();
do {
if (!node) {
break;

}

if (viewer.getParentElement(node) instanceof TextSearchResult) {
viewer.collapse(node);
}
} while (node = navigator.next());

} else {
viewer.collapseAll();
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ export class SearchView extends ViewPane {
const navigator = viewer.navigate();
let node = navigator.first();
do {
if (node && !viewer.isCollapsed(node) && (this.viewModel.hasAIResults || node.id() !== AI_TEXT_SEARCH_RESULT_ID)) {
if (node && !viewer.isCollapsed(node) && (this.shouldShowAIResults() && !(node instanceof TextSearchResult))) {
// ignore the ai text search result id
return true;
}
Expand Down

0 comments on commit 9e32d9e

Please sign in to comment.