Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { ExplorerFolderContext, ExplorerRootContext, FilesExplorerFocusCondition
import { OpenAnythingHandler } from 'vs/workbench/contrib/search/browser/openAnythingHandler';
import { OpenSymbolHandler } from 'vs/workbench/contrib/search/browser/openSymbolHandler';
import { registerContributions as replaceContributions } from 'vs/workbench/contrib/search/browser/replaceContributions';
import { clearHistoryCommand, ClearSearchResultsAction, CloseReplaceAction, CollapseDeepestExpandedLevelAction, copyAllCommand, copyMatchCommand, copyPathCommand, FocusNextInputAction, FocusNextSearchResultAction, FocusPreviousInputAction, FocusPreviousSearchResultAction, focusSearchListCommand, getSearchView, openSearchView, OpenSearchViewletAction, RefreshAction, RemoveAction, ReplaceAction, ReplaceAllAction, ReplaceAllInFolderAction, ReplaceInFilesAction, toggleCaseSensitiveCommand, toggleRegexCommand, toggleWholeWordCommand, FindInFilesCommand, ToggleSearchOnTypeAction, OpenResultsInEditorAction, RerunEditorSearchAction, RerunEditorSearchWithContextAction } from 'vs/workbench/contrib/search/browser/searchActions';
import { clearHistoryCommand, ClearSearchResultsAction, CloseReplaceAction, CollapseDeepestExpandedLevelAction, copyAllCommand, copyMatchCommand, copyPathCommand, FocusNextInputAction, FocusNextSearchResultAction, FocusPreviousInputAction, FocusPreviousSearchResultAction, focusSearchListCommand, getSearchView, openSearchView, OpenSearchViewletAction, RefreshAction, RemoveAction, ReplaceAction, ReplaceAllAction, ReplaceAllInFolderAction, ReplaceInFilesAction, toggleCaseSensitiveCommand, toggleRegexCommand, toggleWholeWordCommand, FindInFilesCommand, ToggleSearchOnTypeAction, OpenResultsInEditorAction, RerunEditorSearchAction, RerunEditorSearchWithContextAction, ExpandAllAction } from 'vs/workbench/contrib/search/browser/searchActions';
import { SearchPanel } from 'vs/workbench/contrib/search/browser/searchPanel';
import { SearchView, SearchViewPosition } from 'vs/workbench/contrib/search/browser/searchView';
import { SearchViewlet } from 'vs/workbench/contrib/search/browser/searchViewlet';
Expand Down Expand Up @@ -634,6 +634,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
});

registry.registerWorkbenchAction(SyncActionDescriptor.create(CollapseDeepestExpandedLevelAction, CollapseDeepestExpandedLevelAction.ID, CollapseDeepestExpandedLevelAction.LABEL), 'Search: Collapse All', category);
registry.registerWorkbenchAction(SyncActionDescriptor.create(ExpandAllAction, ExpandAllAction.ID, ExpandAllAction.LABEL), 'Search: Expand All', category);
registry.registerWorkbenchAction(SyncActionDescriptor.create(ShowAllSymbolsAction, ShowAllSymbolsAction.ID, ShowAllSymbolsAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_T }), 'Go to Symbol in Workspace...');
registry.registerWorkbenchAction(SyncActionDescriptor.create(ToggleSearchOnTypeAction, ToggleSearchOnTypeAction.ID, ToggleSearchOnTypeAction.LABEL), 'Search: Toggle Search on Type', category);
registry.registerWorkbenchAction(SyncActionDescriptor.create(RefreshAction, RefreshAction.ID, RefreshAction.LABEL), 'Search: Refresh', category);
Expand Down
86 changes: 86 additions & 0 deletions src/vs/workbench/contrib/search/browser/searchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,92 @@ export class CollapseDeepestExpandedLevelAction extends Action {
}
}

export class ExpandAllAction extends Action {

static readonly ID: string = 'search.action.expandSearchResults';
static LABEL: string = nls.localize('ExpandAllAction.label', "Expand All");

constructor(id: string, label: string,
@IViewletService private readonly viewletService: IViewletService,
@IPanelService private readonly panelService: IPanelService
) {
super(id, label, 'search-action codicon-chrome-restore');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I add a new codicon for expand-all ?
(codicon-chrome-restore is just a placeholder)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@misolori Can we get expand-all codicon? Probably just collapse-all but with a plus.

this.update();
}

update(): void {
const searchView = getSearchView(this.viewletService, this.panelService);
this.enabled = !!searchView && searchView.hasSearchResults();
}

run(): Promise<void> {
const searchView = getSearchView(this.viewletService, this.panelService);
if (searchView) {
const viewer = searchView.getControl();
viewer.expandAll();
viewer.domFocus();
viewer.focusFirst();
}
return Promise.resolve(undefined);
}
}

export class ToggleCollapseAndExpandAction extends Action {
static readonly ID: string = 'search.action.collapseOrExpandSearchResults';
static LABEL: string = nls.localize('ToggleCollapseAndExpandAction.label', "Toggle Collapse and Expand");

// Cache to keep from crawling the tree too often.
private action: CollapseDeepestExpandedLevelAction | ExpandAllAction | undefined;

constructor(id: string, label: string,
private collapseAction: CollapseDeepestExpandedLevelAction,
private expandAction: ExpandAllAction,
@IViewletService private readonly viewletService: IViewletService,
@IPanelService private readonly panelService: IPanelService
) {
super(id, label, collapseAction.class);
this.update();
}

update(): void {
const searchView = getSearchView(this.viewletService, this.panelService);
this.enabled = !!searchView && searchView.hasSearchResults();
this.onTreeCollapseStateChange();
}

onTreeCollapseStateChange() {
this.action = undefined;
this.determineAction();
}

private determineAction(): CollapseDeepestExpandedLevelAction | ExpandAllAction {
if (this.action !== undefined) { return this.action; }
this.action = this.isSomeCollapsible() ? this.collapseAction : this.expandAction;
this.class = this.action.class;
return this.action;
}

private isSomeCollapsible(): boolean {
const searchView = getSearchView(this.viewletService, this.panelService);
if (searchView) {
const viewer = searchView.getControl();
const navigator = viewer.navigate();
let node = navigator.first();
do {
if (!viewer.isCollapsed(node)) {
return true;
}
} while (node = navigator.next());
}
return false;
}


async run(): Promise<void> {
await this.determineAction().run();
}
}

export class ClearSearchResultsAction extends Action {

static readonly ID: string = 'search.action.clearSearchResults';
Expand Down
20 changes: 16 additions & 4 deletions src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { OpenFileFolderAction, OpenFolderAction } from 'vs/workbench/browser/act
import { ResourceLabels } from 'vs/workbench/browser/labels';
import { IEditor } from 'vs/workbench/common/editor';
import { ExcludePatternInputWidget, PatternInputWidget } from 'vs/workbench/contrib/search/browser/patternInputWidget';
import { CancelSearchAction, ClearSearchResultsAction, CollapseDeepestExpandedLevelAction, RefreshAction, IFindInFilesArgs, OpenResultsInEditorAction, appendKeyBindingLabel } from 'vs/workbench/contrib/search/browser/searchActions';
import { CancelSearchAction, ClearSearchResultsAction, CollapseDeepestExpandedLevelAction, RefreshAction, IFindInFilesArgs, OpenResultsInEditorAction, appendKeyBindingLabel, ExpandAllAction, ToggleCollapseAndExpandAction } from 'vs/workbench/contrib/search/browser/searchActions';
import { FileMatchRenderer, FolderMatchRenderer, MatchRenderer, SearchAccessibilityProvider, SearchDelegate, SearchDND } from 'vs/workbench/contrib/search/browser/searchResultsView';
import { ISearchWidgetOptions, SearchWidget } from 'vs/workbench/contrib/search/browser/searchWidget';
import * as Constants from 'vs/workbench/contrib/search/common/constants';
Expand Down Expand Up @@ -115,6 +115,7 @@ export class SearchView extends ViewPane {
private state: SearchUIState = SearchUIState.Idle;

private actions: Array<CollapseDeepestExpandedLevelAction | ClearSearchResultsAction | OpenResultsInEditorAction> = [];
private toggleCollapseAction: ToggleCollapseAndExpandAction;
private cancelAction: CancelSearchAction;
private refreshAction: RefreshAction;
private contextMenu: IMenu | null = null;
Expand Down Expand Up @@ -144,6 +145,8 @@ export class SearchView extends ViewPane {
private currentSearchQ = Promise.resolve();
private addToSearchHistoryDelayer: Delayer<void>;

private toggleCollapseStateDelayer: Delayer<void>;

constructor(
private position: SearchViewPosition,
options: IViewPaneOptions,
Expand Down Expand Up @@ -206,12 +209,15 @@ export class SearchView extends ViewPane {
this._register(this.searchHistoryService.onDidClearHistory(() => this.clearHistory()));

this.delayedRefresh = this._register(new Delayer<void>(250));

this.addToSearchHistoryDelayer = this._register(new Delayer<void>(2000));
this.toggleCollapseStateDelayer = this._register(new Delayer<void>(100));

const collapseDeepestExpandedLevelAction = this.instantiationService.createInstance(CollapseDeepestExpandedLevelAction, CollapseDeepestExpandedLevelAction.ID, CollapseDeepestExpandedLevelAction.LABEL);
const expandAllAction = this.instantiationService.createInstance(ExpandAllAction, ExpandAllAction.ID, ExpandAllAction.LABEL);

this.actions = [
this._register(this.instantiationService.createInstance(ClearSearchResultsAction, ClearSearchResultsAction.ID, ClearSearchResultsAction.LABEL)),
this._register(this.instantiationService.createInstance(CollapseDeepestExpandedLevelAction, CollapseDeepestExpandedLevelAction.ID, CollapseDeepestExpandedLevelAction.LABEL))
];

if (this.searchConfig.enableSearchEditorPreview) {
Expand All @@ -222,6 +228,7 @@ export class SearchView extends ViewPane {

this.refreshAction = this._register(this.instantiationService.createInstance(RefreshAction, RefreshAction.ID, RefreshAction.LABEL));
this.cancelAction = this._register(this.instantiationService.createInstance(CancelSearchAction, CancelSearchAction.ID, CancelSearchAction.LABEL));
this.toggleCollapseAction = this._register(this.instantiationService.createInstance(ToggleCollapseAndExpandAction, ToggleCollapseAndExpandAction.ID, ToggleCollapseAndExpandAction.LABEL, collapseDeepestExpandedLevelAction, expandAllAction));
}

getContainer(): HTMLElement {
Expand Down Expand Up @@ -390,6 +397,7 @@ export class SearchView extends ViewPane {

this.refreshAction.update();
this.cancelAction.update();
this.toggleCollapseAction.update();

super.updateActions();
}
Expand Down Expand Up @@ -699,6 +707,9 @@ export class SearchView extends ViewPane {
}
}));
this._register(this.tree.onContextMenu(e => this.onContextMenu(e)));
this._register(this.tree.onDidChangeCollapseState(() =>
this.toggleCollapseStateDelayer.trigger(() => this.toggleCollapseAction.onTreeCollapseStateChange())
));

const resourceNavigator = this._register(new TreeResourceNavigator2(this.tree, { openOnFocus: true, openOnSelection: false }));
this._register(Event.debounce(resourceNavigator.onDidOpenResource, (last, event) => event, 75, true)(options => {
Expand Down Expand Up @@ -1707,7 +1718,8 @@ export class SearchView extends ViewPane {
this.state === SearchUIState.SlowSearch ?
this.cancelAction :
this.refreshAction,
...this.actions
...this.actions,
this.toggleCollapseAction
];
}

Expand Down