Skip to content

Commit

Permalink
feat. add a menu item 'Expand All' to expand subtree
Browse files Browse the repository at this point in the history
  • Loading branch information
pagict committed Apr 2, 2024
1 parent 6394792 commit 10dc3e8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/vs/workbench/contrib/search/browser/searchActionsFind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ registerAction2(class RestrictSearchToFolderAction extends Action2 {
}
});


registerAction2(class ExpandSelectedTreeCommandAction extends Action2 {
constructor(
) {
super({
id: Constants.SearchCommandIds.ExpandSelectedTreeCommandId,
title: nls.localize('search.expandAll', "Expand All"),
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<any> {
await expandSelectSubtree(accessor);
}
});

registerAction2(class ExcludeFolderFromSearchAction extends Action2 {
constructor() {
super({
Expand Down Expand Up @@ -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);
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 @@ -38,6 +38,7 @@ export const enum SearchCommandIds {
ToggleSearchOnTypeActionId = 'workbench.action.toggleSearchOnType',
CollapseSearchResultsActionId = 'search.action.collapseSearchResults',
ExpandSearchResultsActionId = 'search.action.expandSearchResults',
ExpandSelectedTreeCommandId = 'search.action.expandSelected',
ClearSearchResultsActionId = 'search.action.clearSearchResults',
ViewAsTreeActionId = 'search.action.viewAsTree',
ViewAsListActionId = 'search.action.viewAsList',
Expand Down

0 comments on commit 10dc3e8

Please sign in to comment.