Skip to content

Commit 520423b

Browse files
committed
Custom tree view should run command on every click
Not just on selection change Fixes microsoft#76998
1 parent 7c91227 commit 520423b

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

src/vs/workbench/browser/parts/views/customView.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { URI } from 'vs/base/common/uri';
2828
import { dirname, basename } from 'vs/base/common/resources';
2929
import { LIGHT, FileThemeIcon, FolderThemeIcon, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
3030
import { FileKind } from 'vs/platform/files/common/files';
31-
import { WorkbenchAsyncDataTree } from 'vs/platform/list/browser/listService';
31+
import { WorkbenchAsyncDataTree, TreeResourceNavigator2 } from 'vs/platform/list/browser/listService';
3232
import { ViewletPanel, IViewletPanelOptions } from 'vs/workbench/browser/parts/views/panelViewlet';
3333
import { localize } from 'vs/nls';
3434
import { timeout } from 'vs/base/common/async';
@@ -42,7 +42,7 @@ import { IMarkdownRenderResult } from 'vs/editor/contrib/markdown/markdownRender
4242
import { ILabelService } from 'vs/platform/label/common/label';
4343
import { Registry } from 'vs/platform/registry/common/platform';
4444
import { IListVirtualDelegate, IIdentityProvider } from 'vs/base/browser/ui/list/list';
45-
import { ITreeRenderer, ITreeNode, IAsyncDataSource, ITreeContextMenuEvent, ITreeEvent } from 'vs/base/browser/ui/tree/tree';
45+
import { ITreeRenderer, ITreeNode, IAsyncDataSource, ITreeContextMenuEvent } from 'vs/base/browser/ui/tree/tree';
4646
import { FuzzyScore, createMatches } from 'vs/base/common/filters';
4747
import { CollapseAllAction } from 'vs/base/browser/ui/tree/treeDefaults';
4848

@@ -389,7 +389,6 @@ export class CustomTreeView extends Disposable implements ITreeView {
389389
aligner.tree = this.tree;
390390

391391
this.tree.contextKeyService.createKey<boolean>(this.id, true);
392-
this._register(this.tree.onDidChangeSelection(e => this.onSelection(e)));
393392
this._register(this.tree.onContextMenu(e => this.onContextMenu(treeMenus, e)));
394393
this._register(this.tree.onDidChangeSelection(e => this._onDidChangeSelection.fire(e.elements)));
395394
this._register(this.tree.onDidChangeCollapseState(e => {
@@ -401,6 +400,18 @@ export class CustomTreeView extends Disposable implements ITreeView {
401400
}
402401
}));
403402
this.tree.setInput(this.root).then(() => this.updateContentAreas());
403+
404+
const customTreeNavigator = new TreeResourceNavigator2(this.tree);
405+
this._register(customTreeNavigator);
406+
this._register(customTreeNavigator.onDidOpenResource(e => {
407+
if (!e.browserEvent) {
408+
return;
409+
}
410+
const selection = this.tree.getSelection();
411+
if ((selection.length === 1) && selection[0].command) {
412+
this.commandService.executeCommand(selection[0].command.id, ...(selection[0].command.arguments || []));
413+
}
414+
}));
404415
}
405416

406417
private onContextMenu(treeMenus: TreeMenus, treeEvent: ITreeContextMenuEvent<ITreeItem>): void {
@@ -599,20 +610,6 @@ export class CustomTreeView extends Disposable implements ITreeView {
599610
this.domNode.removeAttribute('tabindex');
600611
}
601612
}
602-
603-
private onSelection(e: ITreeEvent<ITreeItem>): void {
604-
if (!e.browserEvent) {
605-
return;
606-
}
607-
const selection: ITreeItem = this.tree.getSelection()[0];
608-
if (selection) {
609-
if (selection.command) {
610-
if (this.tree.openOnSingleClick) {
611-
this.commandService.executeCommand(selection.command.id, ...(selection.command.arguments || []));
612-
}
613-
}
614-
}
615-
}
616613
}
617614

618615
class CustomViewIdentityProvider implements IIdentityProvider<ITreeItem> {

0 commit comments

Comments
 (0)