microsoft / microsoft/vscode

Allow TreeItem.command to declare an alternative command for modifier-click

Open
#336,540 0 comments 0 reactions 1 assignee Claimed by @alexr00 View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

### Problem

A `TreeItem` can declare a single `command`, executed when the user clicks the item's label. There is no way to declare a different command for a modifier-click (Alt/Ctrl/Cmd), so extensions that expose a "primary action" and a closely-related variant must either pick one as the click behaviour, or ship a setting that flips it globally.

The common shape of this is "open" vs "open in a new window" / "open to the side": conventional in tabbed UIs, and something users expect to work by habit.

### Why this is a gap rather than a new concept

VS Code already has exactly this concept, one level down. The `menus` contribution point accepts an `alt` key, documented as the identifier of an alternative command to run, which must itself be declared in the `commands` section. So an inline action *button* on a tree item can already have an alt behaviour, while the tree item's own click cannot. The proposal is only to close that asymmetry.

### Proposal

Let `TreeItem.command` be paired with an optional alternative, e.g.:

```ts
treeItem.command = { command: 'ext.open', title: '', arguments: [x] };
treeItem.altCommand = { command: 'ext.openInNewWindow', title: '', arguments: [x] };
```

Semantics mirroring `menus.alt`: when the modifier is held at click time, the alternative runs instead. Extensions that don't set it are unaffected.

### Alternatives considered

- **A setting per extension.** Works, but it's a global flip rather than a per-click choice, and every extension reinvents it with a different name.
- **Inline action buttons.** Already used, and fine as a discoverable fallback, but they require hitting a small target on the right edge of the row instead of the row itself — which is the ergonomic problem being reported.
- **`window.openFoldersInNewWindow`.** Solves the folder-opening case specifically, but it is global and changes native behaviour (`File > Open Folder`, Recent, `code .`), so it isn't scoped to the tree the user is actually clicking in.

### Related

- #18064 — the same request for QuickPick items (open since 2017)
- #130880 — key bindings on tree view items
- Downstream example: alefragnani/vscode-project-manager#825 and #817

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.