Skip to content
Open
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
48 changes: 47 additions & 1 deletion src/vs/workbench/contrib/search/browser/searchActionsFind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { Schemas } from '../../../../base/common/network.js';
import { IEditorGroupsService } from '../../../services/editor/common/editorGroupsService.js';
import { IEditorService } from '../../../services/editor/common/editorService.js';
import { forcedExpandRecursively } from './searchActionsTopBar.js';
import { RenderableMatch, ISearchTreeFileMatch, ISearchTreeFolderMatchWithResource, ISearchResult, isSearchTreeFileMatch, isSearchTreeMatch } from './searchTreeModel/searchTreeCommon.js';
import { RenderableMatch, ISearchTreeFileMatch, ISearchTreeFolderMatchWithResource, ISearchResult, isSearchTreeFileMatch, isSearchTreeMatch, isSearchResult } from './searchTreeModel/searchTreeCommon.js';

//#region Interfaces
export interface IFindInFilesArgs {
Expand Down Expand Up @@ -104,6 +104,52 @@ registerAction2(class ExpandSelectedTreeCommandAction extends Action2 {
}
});


registerAction2(class CollapseOtherResultsAction extends Action2 {
constructor() {
super({
id: Constants.SearchCommandIds.CollapseOtherSearchResultsActionId,
title: nls.localize('search.collapseOtherResults', "Collapse Other Results"),
category,
menu: [{
id: MenuId.SearchContext,
when: ContextKeyExpr.and(
ContextKeyExpr.or(Constants.SearchContext.FolderFocusKey, Constants.SearchContext.FileFocusKey),
Constants.SearchContext.HasSearchResults
),
group: 'search',
order: 5
}]
});
}

override async run(accessor: ServicesAccessor) {
const viewsService = accessor.get(IViewsService);
const searchView = getSearchView(viewsService);
if (!searchView) {
return;
}

const viewer = searchView.getControl();
const focusedElements = viewer.getFocus();
if (!focusedElements.length) {
return;
}

const focusedElement = focusedElements[0];
if (!focusedElement) {
return;
}

const parentElement = focusedElement.parent();
const parentNode = viewer.getNode(isSearchResult(parentElement) ? undefined : parentElement);
for (const child of parentNode.children) {
if (child.element && !isSearchResult(child.element) && child.element !== focusedElement && viewer.hasNode(child.element) && !viewer.isCollapsed(child.element)) {
viewer.collapse(child.element, true);
}
}
}
});
registerAction2(class ExcludeFolderFromSearchAction extends Action2 {
constructor() {
super({
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/search/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const enum SearchCommandIds {
CollapseSearchResultsActionId = 'search.action.collapseSearchResults',
ExpandSearchResultsActionId = 'search.action.expandSearchResults',
ExpandRecursivelyCommandId = 'search.action.expandRecursively',
CollapseOtherSearchResultsActionId = 'search.action.collapseOtherResults',
ClearSearchResultsActionId = 'search.action.clearSearchResults',
GetSearchResultsActionId = 'search.action.getSearchResults',
ViewAsTreeActionId = 'search.action.viewAsTree',
Expand Down