Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make fully collapsed state up to under Text Results or AI Results #230420

Merged
merged 1 commit into from
Oct 3, 2024
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
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
Loading