I can add a command to activate when an item is selected, but I want the same behavior as the in-built explorer where single click opens the tab with the file (title in italics) and double click opens it permanently as a new tab.
Can this be added to the TreeDataProvider interface?
@sandy081 A similar issue: https://github.com/microsoft/vscode/issues/39601 was closed, but I would love to revisit this. As this behavior (single click to open a preview and double to pin it) is IMO an expected behavior by our users -- as the file explorer, SCM, search, all provide this behavior.
ahh sorry, I only searched the open issues, not the closed one.
This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
:slightly_smiling_face: This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
@alexr00 would be great if we can put this on the radar, given https://github.com/microsoft/vscode/issues/109779 which is based on feedback we got from users.
The current logic is to execute the item's command:
@eamodio you seem to have a similar case as well here:
I wonder if we should simply pass over the editor options to the command? That is very subtle though and extensions would probably forget to adopt this.
//cc @jrieken for https://github.com/microsoft/vscode/issues/101522
@bpasero this issue is about adding API for the tree for double click. It is up to the user what command they want to execute.
@alexr00 I am not sure I would agree, from the OP:
I can add a command to activate when an item is selected, but I want the same behavior as the in-built explorer where single click opens the tab with the file (title in italics) and double click opens it permanently as a new tab.
There are more conditions under which an editor opens as non-preview:
Enter)@dkdaddy fyi maybe you could clarify the request is about preview/non-preview behaviour and not so much about double click?
In order for extension authors to add a command to execute on double click, we first need to add double click to the API. Then they can use whatever command they want on double click, including a command (if it exists) that opens a file in non-preview.
Ok, now I understand what you're saying. After discussion, our proposal is not to change the API surface but instead to always append an additional parameter to the command and document it:
/**
* The [command](#Command) that should be executed when the tree item is selected.
* NEW: The last [arg](#Command#args) for tree items that are resources will be the
* `options` for `vscode.open` as described in the [documentation](https://code.visualstudio.com/api/references/commands). This is intended to provide extensions with an
* easy way to follow VS Codes default or set open options.
*/
command?: Command;
@joaomoreno reminded me that the SCM changes view should also benefit from our solution.
What has been discussed so far
vscode.open during its executionvscode.open-command as their tree command get the special treatmentAPI call input for discussion:
// ######## A: registerTreeViewCommand ##########
export function registerTreeViewCommand(command: string, callback: (treeView: TreeView<any>, options: TextDocumentShowOptions, ...args: any[]) => void, thisArg?: any): Disposable;
// ######## B: registerOpenableCommand ##########
export function registerOpenableCommand(command: string, callback: (options: TextDocumentShowOptions, ...args: any[]) => void, thisArg?: any): Disposable;
// Maybe more generic with an extra interface OpenableContext to be able to add more in the future?
// ######### C: TreeContextAwareCommand ############
export interface TreeContextAwareCommand {
command: Command; // will get TextDocumentShowOptions pass in as argument
}
export class TreeItemVariantA {
command?: Command | TreeContextAwareCommand;
}
// ######### D: vscode.open ############
export class TreeItemVariantB {
command?: Command | 'vscode.open'; // will take the `resourceUri` if provided and pass TextDocmentShowOptions accordingly
}
// ######### E: Event on Item ############
export interface TreeItemDidOpenEvent {
options: TextDocumentShowOptions;
}
export class TreeItemVariantC extends TreeItem {
onDidOpen: Event<TreeItemDidOpenEvent>;
}
// ######## F: Event on TreeView ##########
export interface TreeViewDidOpenEvent {
item: TreeItem;
options: TextDocumentShowOptions;
}
export interface TreeView2<T> extends TreeView<T> {
onDidOpen: Event<string>;
}
// ######## G: Arguments/Proxy Trick Hack ##########
const treeItem: TreeItem = {
command: {
command: 'my.open',
title: 'Open',
arguments: [treeItemUri, <some tree proxy static that returns TextDocumentShowOptions?>]
}
}
//#endregion
API call results: we will update the documentation in the API that vscode.open and vscode.diff are the preferred commands to use for a custom tree item. When they are used, we will make sure to pass in the correct TextDocumentShowOptions based on the way how the tree item was clicked. We will validate this approach by adopting it for our built in extensions such as @jrieken 's references view.
I have pushed changes to the references viewlet to make it use vscode.open with arguments. That should allow to go forward on this. However, this _currently_ uses preserveFocus: true to preserve the existing behaviour. My expectation is that this won't be needed anymore once the tree does its magic.
I tried to adopt this but failed, because commands on the main side are generated:

My wip changes are in https://github.com/microsoft/vscode/commit/fd968feeea7e0136278d915fbcdc3503fe6aadf0 that naively assumed that vscode.open is the command in use.
I need some help to know how to proceed as I have not a lot of knowledge in this commands area on the ext host.
I really like this solution that whenever using vscode.open, the open args will be passed around automatically. 馃憦
I'd love if we generalize it for contributable commands to behave just like vscode.open: there should be a way for them to also demand open args to be passed when invoked from a list/tree. That way we can further fix git and gitlens.
I need some feedback in https://github.com/microsoft/vscode/pull/110398
One additional idea that shouldn't get lost is a special argument for open-commands that allows lazy resolving. That's an alternative to resolveTreeItem and would also work for SCM and the timeline. Like a promise or a callback returning a promise that will resolve to the actual arguments.
I have also created https://github.com/microsoft/vscode/issues/110459 which explores ideas to make the API commands more visible to our tooling. 鉃★笍 TypeScript brains welcome!
@jrieken I think you can remove your handling of preserveFocus now. I pushed my changes.
As extension author: use vscode.open or vscode.diff commands for your TreeItem to get the same treatment as built-in views have.
Most helpful comment
This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!