question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Key binding on view item command doesn't provide the view item

See original GitHub issue

Issue Type: Bug

This is easily reproducible using the tree-view-sample repo.

  1. Add a key binding for nodeDependencies.editEntry
  2. Open the package explorer view and click on one of the nodes
  3. 🐛 execute the key binding and notice the command fails (while if you click the pencil icon it will work fine)

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® Core™ i7-6700K CPU @ 4.00GHz (8 x 4008)
GPU Status 2d_canvas: enabled
checker_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%

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
joaomorenocommented, Dec 9, 2020

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.

1reaction
joaomorenocommented, Dec 8, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

C#/WPF: KeyBinding not triggering Command - Stack Overflow
In 3.5 its "feature". UserControl.InputBindings is not part of dataContext tree so you cannot bind to items of class, that is bound to...
Read more >
when clause contexts | Visual Studio Code Extension API
For example, VS Code uses when clauses to enable or disable command keybindings, which you can see in the Default Keybindings JSON (Preferences:...
Read more >
Mac keyboard shortcuts - Apple Support
Command -1: View the items in the Finder window as icons. Command-2: View the items in a Finder window as a list.
Read more >
Keybinds - Rust Wiki
This keybind will flip the view model of the item you're holding in your hand ... Creating a bind combining these commands will...
Read more >
Layouts and binding expressions | Android Developers
This view element is what your root would be in a non-binding layout file. The following code shows a sample layout file: <?xml...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found