向“when"添加条件来自 VS 代码扩展? [英] Adding conditions to "when" from VS-code extension?

查看:25
本文介绍了向“when"添加条件来自 VS 代码扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去 20 年我一直在使用的代码编辑器(codewright)允许您设置选择模式".设置后,所有键盘光标移动都会扩展选择.在 VS Code 中,您可以通过按住 shift 键(例如,Shift 向下箭头)来扩展选择范围,但我正在寻找一种无需使用 shift 键的方法.

The code editor I've been using for the past 20 years (codewright) allows you to set a "select mode". When that is set, all keyboard cursor movements extend the selection. In VS Code, you can extend the selection by holding down the shift key (for example, Shift down-arrow), but I am looking for a way to do that without the shift key.

我已经编写了一个主要用于它的扩展,但是如果我可以为 keybindings.json 中的when"子句创建一个新条件,我将不得不做的工作要少得多.例如,我本来想改变

I have written an extension that mostly does it, but I would have had to do far less work if I could have created a new condition for the "when" clause in keybindings.json. For example, I would have liked to change

{ "key": "shift+down",    "command": "cursorDownSelect",
                          "when": "editorTextFocus" },

类似的东西

{ "key": "down",    "command": "cursorDownSelect",
                    "when": "editorTextFocus || extensionSelectionMode" },
{ "key": "down",    "command": "cursorDown",
                    "when": "editorTextFocus" },

有没有办法从扩展中添加这样的条件?

Is there a way to do add a such a condition from an extension?

推荐答案

尝试在您的扩展中使用 setContext 命令:

Try using the setContext command in your extension:

vscode.commands.executeCommand('setContext', 'extensionSelectionMode', true)

请参阅 VSCode vim 以了解此操作的示例

See VSCode vim for an example of this in action

我们正在跟踪更好的 API 以在此处设置上下文:https://github.com/Microsoft/vscode/issues/10471

We are tracking a better API for setting contexts here: https://github.com/Microsoft/vscode/issues/10471

这篇关于向“when"添加条件来自 VS 代码扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆