简单的按键绑定无法按预期工作 [英] Simple keybind not working as expected

查看:70
本文介绍了简单的按键绑定无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将 ctrl + x 绑定到 editor.action.clipboardCutAction (剪切),但条件是仅在选择文本时才调用它.

I'm trying to bind ctrl+x to editor.action.clipboardCutAction (cut), but with the condition that it is only invoked when text is selected.

但是,它不起作用.当未选择任何文本时,它仍会剪切整行.

However, it is not working. It still cuts the whole line when no text is selected.

代码:

"key": "ctrl+x",
"command": "editor.action.clipboardCutAction",
"when": "editorTextFocus && editorHasSelection && !editorReadonly"

推荐答案

临时解决方案

作为临时解决方案,您可以先重新分配此快捷方式.例如:

Temporary solution

As a temporary solution you can reassign this shortcut first. For example:

{
    "key": "ctrl+x",
    "command": "workbench.action.closeMessages",
},
{
    "key": "ctrl+x",
    "command": "editor.action.clipboardCutAction",
    "when": "editorTextFocus && editorHasSelection && !editorReadonly"
},

您可以使用另一个命令来代替命令 workbench.action.closeMessages .

Instead of command workbench.action.closeMessages, you can use another.

如果未选择任何内容,则按 ctrl + x 将执行第一个组合键并运行 workbench.action.closeMessages 命令.

If nothing is selected then pressing ctrl+x will execute first key combination and run workbench.action.closeMessages command.

在设置 ctrl +,中添加以下内容:

In settings ctrl+, add following:

// Controls whether copying without a selection copies the current line.
"editor.emptySelectionClipboard": false,

替代解决方案的缺点

复制时也可以使用.

Disadvantage of alternative solution

Also works when copying.

这篇关于简单的按键绑定无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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