Visual Studio Code 扩展如何直接添加键绑定
Visual Studio Code 扩展如何直接将键绑定添加到工作区?
How can a Visual Studio Code extension add key bindings to a workspace directly?
所有设置都应包含在扩展程序中,以便扩展程序所做的任何修改都可以轻松地在 1 个地方找到,卸载扩展程序将删除所有修改.
All settings should be contained within the extension, so that any modifications by the extension are easy to find in 1 place, and uninstalling the extension will remove any modifications.
我正在开发一个需要监听按键的 VSCode 扩展.这个问题通过vscode.workspace.onDidChangeTextDocument 事件,但我发现与仅为我在听什么.我找到了一种非常优雅的方式来使用键绑定实现我想要的,但实现不可扩展,也不能简单地导出供其他人实现.
I'm developing a VSCode extension which will need to listen for keystrokes. This question listens through the vscode.workspace.onDidChangeTextDocument event, but I found that route a little messy in comparison to just creating key bindings for what I'm listening to. I found a pretty elegant way to achieve what I want using key bindings, but the implementation is not scalable and not simply exportable for others to implement.
因此,我想编写一个完全封装任何必要的键绑定添加的扩展.
Therefore I want to write an extension that totally encapsulates any key binding additions that are necessary.
经过一夜的研究,我确实找到了这个问题的答案,所以我只想发布解决方案以造福他人.
I did find the answer to this after a long night of research, so I just want to post the solution for others' benefit.
https://code.visualstudio.com/api/references/contribution-points#contributes.keybindings
这允许在扩展的 package.json 中声明新的键绑定
This allows new keybindings to be declared right in the extension's package.json