diff --git a/src/vs/workbench/contrib/search/browser/searchActionsFind.ts b/src/vs/workbench/contrib/search/browser/searchActionsFind.ts index c2e313827bf39..2051b1d13741b 100644 --- a/src/vs/workbench/contrib/search/browser/searchActionsFind.ts +++ b/src/vs/workbench/contrib/search/browser/searchActionsFind.ts @@ -77,6 +77,31 @@ registerAction2(class RestrictSearchToFolderAction extends Action2 { } }); + +registerAction2(class ExpandSelectedTreeCommandAction extends Action2 { + constructor( + ) { + super({ + id: Constants.SearchCommandIds.ExpandRecursivelyCommandId, + title: nls.localize('search.expandRecursively', "Expand Recursively"), + category, + menu: [{ + id: MenuId.SearchContext, + when: ContextKeyExpr.and( + ContextKeyExpr.or(Constants.SearchContext.FileFocusKey, Constants.SearchContext.FolderFocusKey), + Constants.SearchContext.HasSearchResults + ), + group: 'search', + order: 4 + }] + }); + } + + override async run(accessor: any): Promise { + await expandSelectSubtree(accessor); + } +}); + registerAction2(class ExcludeFolderFromSearchAction extends Action2 { constructor() { super({ @@ -270,6 +295,16 @@ registerAction2(class FindInWorkspaceAction extends Action2 { }); //#region Helpers +function expandSelectSubtree(accessor: ServicesAccessor) { + const viewsService = accessor.get(IViewsService); + const searchView = getSearchView(viewsService); + if (searchView) { + const viewer = searchView.getControl(); + const selected = viewer.getFocus()[0]; + viewer.expand(selected, true); + } +} + async function searchWithFolderCommand(accessor: ServicesAccessor, isFromExplorer: boolean, isIncludes: boolean, resource?: URI, folderMatch?: FolderMatchWithResource) { const listService = accessor.get(IListService); const fileService = accessor.get(IFileService); diff --git a/src/vs/workbench/contrib/search/common/constants.ts b/src/vs/workbench/contrib/search/common/constants.ts index a7f7c53b660e8..aa4e615b115b2 100644 --- a/src/vs/workbench/contrib/search/common/constants.ts +++ b/src/vs/workbench/contrib/search/common/constants.ts @@ -38,6 +38,7 @@ export const enum SearchCommandIds { ToggleSearchOnTypeActionId = 'workbench.action.toggleSearchOnType', CollapseSearchResultsActionId = 'search.action.collapseSearchResults', ExpandSearchResultsActionId = 'search.action.expandSearchResults', + ExpandRecursivelyCommandId = 'search.action.expandRecursively', ClearSearchResultsActionId = 'search.action.clearSearchResults', ViewAsTreeActionId = 'search.action.viewAsTree', ViewAsListActionId = 'search.action.viewAsList',