Open eamodio opened 5 years ago
Any news on this? I Hope to see this on a near future mile-stone. This have been in On deck
for too long...
This is not working for me as well, when trying to set a keybinding for a command on a particular node.contextValue, ie:
{
"command": "custom.extension.command",
"key": "ctrl+alt+z",
"mac": "cmd+alt+z",
"when": "sideBarFocus && focusedView == custom.view && viewItem =~ /nodeContextHere/"
},
But this works if I remove && viewItem =~ /contextHere/
🤣 I was about to file this issue again and found that I already had. This is very problematic for extensions wanting to allow key bindings tree items. And it is likely confusing to users -- because if they set a key binding for a command that is in a tree item's context menu, then the shortcut key shows up in the context menu, but it won't work -- because the command will get executed without any context.
@alexr00 can you point to the likely place where changes would need to be made to make this happen?
Although, I this problem is bigger than just contributed tree view -- our built-in trees (explorer, scm, etc) all have the same issue
/cc @alexdima
I'm not sure where the changes would need to be made. Maybe @alexdima or @joaomoreno knows.
When the command gets executed from the key binding it isn't getting the proper context.
What the the expected context? That somehow viewItem
is the selected/focused tree item? If so, the custom tree view needs to create a scoped context key service in which it sets the viewItem
context as the tree selection/focus changes. That way, the context will be set when the user invokes the keybinding and has DOM focus inside the custom tree view DOM element.
Thanks @joaomoreno!
@joaomoreno is this something the list widget could do itself? Since this issue affects all our trees, whether custom or not. (Though I guess the actual context is different for each)
Yes. We could potentially have a sort of IContextKeysProvider
feature at the Workbench(List|Tree)
level which would do this for you. Something like:
interface IContextKeysProvider<T> {
getContextKeys(element: T) { key: string, value: string }[];
}
Or so.
@joaomoreno who should own that? Should we turn this issue into that?
I wouldn't mind a contribution! ;)
Issue Type: Bug
This is easily reproducible using the
tree-view-sample
repo.nodeDependencies.editEntry
When the command gets executed from the key binding it isn't getting the proper context. This breaks most key bindings for commands on view items.
/cc @jrieken
VS Code version: Code 1.33.1 (51b0b28134d51361cf996d2f0a1c698247aeabd8, 2019-04-11T08:27:14.102Z) OS version: Windows_NT x64 10.0.18362
System Info
|Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz (8 x 4008)| |GPU Status|2d_canvas: enabledchecker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled| |Memory (System)|31.93GB (15.81GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|