Skip to content

Commit b02e2ef

Browse files
committed
Fix "reveal in sidebar" search command with no context
Fix microsoft#94827
1 parent c677d9e commit b02e2ef

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

src/vs/workbench/contrib/search/browser/search.contribution.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,21 +332,37 @@ CommandsRegistry.registerCommand({
332332

333333
CommandsRegistry.registerCommand({
334334
id: Constants.RevealInSideBarForSearchResults,
335-
handler: (accessor, fileMatch: FileMatch) => {
335+
handler: (accessor, args: any) => {
336336
const viewletService = accessor.get(IViewletService);
337337
const explorerService = accessor.get(IExplorerService);
338338
const contextService = accessor.get(IWorkspaceContextService);
339-
const uri = fileMatch.resource;
339+
340+
const searchView = getSearchView(accessor.get(IViewsService));
341+
if (!searchView) {
342+
return;
343+
}
344+
345+
let fileMatch: FileMatch;
346+
if (!(args instanceof FileMatch)) {
347+
args = searchView.getControl().getFocus()[0];
348+
}
349+
if (args instanceof FileMatch) {
350+
fileMatch = args;
351+
} else {
352+
return;
353+
}
340354

341355
viewletService.openViewlet(VIEWLET_ID_FILES, false).then((viewlet) => {
342-
const explorerViewContainer = viewlet?.getViewPaneContainer() as ExplorerViewPaneContainer;
356+
if (!viewlet) {
357+
return;
358+
}
343359

360+
const explorerViewContainer = viewlet.getViewPaneContainer() as ExplorerViewPaneContainer;
361+
const uri = fileMatch.resource;
344362
if (uri && contextService.isInsideWorkspace(uri)) {
345-
const explorerView = explorerViewContainer?.getExplorerView();
346-
if (explorerView) {
347-
explorerView.setExpanded(true);
348-
explorerService.select(uri, true).then(() => explorerView.focus(), onUnexpectedError);
349-
}
363+
const explorerView = explorerViewContainer.getExplorerView();
364+
explorerView.setExpanded(true);
365+
explorerService.select(uri, true).then(() => explorerView.focus(), onUnexpectedError);
350366
}
351367
});
352368
}

0 commit comments

Comments
 (0)