【问题标题】:How to check if the text in an editor has focus when developing an extension?开发扩展时如何检查编辑器中的文本是否有焦点?
【发布时间】:2021-06-27 06:35:11
【问题描述】:

editorTextFocus相同,但我想在开发扩展时检查这种情况,API 是什么?

我尝试了以下方法:

if (window.activeTextEditor) {
  // ...
}

但是结果和使用editorTextFocus不一样。

【问题讨论】:

  • vscode.workspace.activeTextEditor
  • @rioV8 属性“activeTextEditor”在类型“typeof workspace”上不存在。ts(2339)
  • 如果您在 API 文档中搜索 activeTextEditor 会怎样
  • @rioV8 根据我的搜索,它没有像hasTextFocus 这样的方法。
  • 因为activeTextEditor 是焦点

标签: visual-studio-code vscode-extensions vscode-keybinding


【解决方案1】:

所以我想要一个类似于getContext API 的东西,它是setContext API 的必然结果,在这种情况下,我会像getContext('editorTextFocus') 一样使用它。

经过大量搜索,我最终得到了这个Add getContext command PR,但由于these reasons而被拒绝,基本上是说getContext API不是解决此类问题的方法。我想我们必须等到 VSCode 团队为此提出更好的 API,希望不会花费太长时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多