VS Code-查找面板/视图上下文名称以获取“何时"快捷方式 [英] VS Code - find panel/view context name for shortcut 'when' expression

查看:84
本文介绍了VS Code-查找面板/视图上下文名称以获取“何时"快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的VS Code实例添加一些快捷方式,并且我想使用when表达式来限制它们的范围,以避免冲突.

I'm trying to add some shortcuts to my VS Code instance and I want to scope them using the when expression to avoid conflicts.

A,我正在努力寻找在表达式中使用的正确上下文名称,以实现所需的内容.

Alas, I'm struggling to find the right context name to use in the expression to achieve what I want.

我搜索了文档,发现其中列出了许多文档: https://code.visualstudio.com/docs/getstarted/keybindings#_contexts

I've searched the documentation and found that a number of them are listed here: https://code.visualstudio.com/docs/getstarted/keybindings#_contexts

但是,正如文档所述:

上面的列表并不详尽,并且在默认键盘快捷键"中特定VS Code UI的上下文时,您可能会看到一些内容.

The list above isn't exhaustive and you may see some when contexts for specific VS Code UI in the Default Keyboard Shortcuts.

当然,我想将快捷方式作用于其上的上下文不在列表中;)

Of course, the context to which I want to scope my shortcuts is not on the list ;)

因此,我想知道是否有一种方法可以在VS Code用户界面中找到特定面板/视图的上下文名称.

为了说明这一点,假设我只想在列出可用NPM脚本的面板集中显示一个快捷方式时才使用该快捷方式...应该使用什么上下文名称来实现?

To illustrate this, suppose I'd like to make a shortcut active only when the panel that lists the available NPM scripts is focused... What context name should be used to achieve that?

推荐答案

我尝试了此操作-没想到它可以工作-但它似乎可以:

I tried this - not expecting it to work - but it seems to:

"when": "focusedView == npm"

相似信息为有效/重点视图上下文子句.

通常,您可以:

  1. 打开开发人员工具
  2. 在VS Code命令面板中选择Inspect Context Keys
  3. 在vscode窗口中单击一个元素
  4. 在工具控制台中查看并展开其中的最后一项,以显示所有当前上下文(当子句时).
  1. Open the developer tools
  2. Choose Inspect Context Keys in the VS Code Command Palette
  3. Click on an element in the vscode window
  4. Look in the tools console and expand the last item therein to show all the current context (when clauses).

但是当我这样做时,我发现没有任何帮助,并且focusedView = ""在那儿,所以没有帮助.

But when I did that I didn't find anything helpful and focusedView = "" was there, so that's not helpful.

所以我刚刚尝试了

{
  "key": "alt+i",
  "command": "workbench.action.terminal.sendSequence",
  "args": { "text": "howdy" },
  "when": "focusedView == npm"
},

只是将howdy打印到终端以进行测试..我唯一能使它工作的方法是当npm scripts viewlet标头或其内容具有焦点时.

that just prints howdy to the terminal for testing.. And the only way I could get it to work was when the npm scripts viewlet header or its contents had focus.

这篇关于VS Code-查找面板/视图上下文名称以获取“何时"快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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