代码之家  ›  专栏  ›  技术社区  ›  starball Martin Jorgensen

在VS Code中,是否有键盘快捷键命令用于在输入框(而不是编辑器)中键入指定文本?

  •  0
  • starball Martin Jorgensen  · 技术社区  · 1 年前

    我想编写一个键绑定,以便在VS Code中的非编辑器输入框中键入内容,例如搜索视图中的查询编辑器输入框或编辑器查找小部件。

    我试着用 "type" 命令如下:

    {
        "key": ...,
        "command": "type",
        "args": { "text": "hello world" }
    },
    

    但这并没有达到我的预期。它在搜索视图的查询编辑器输入框中似乎没有效果,而在编辑器查找小部件的输入框中,它最终将文本参数键入编辑器本身,所以我认为这个命令只是用于在编辑器中键入。

    如何做到这一点?(理想情况下不使用扩展,但使用扩展的答案仍然是可以接受的)还是根本不可能?


    我试着用谷歌搜索“ github vscode issues keyboard shortcut "type" into input box “在顶部搜索结果中没有看到任何有用的内容。也没有用于搜索” is:q keyboard shortcut [vscode] type input box “在Stack Overflow的搜索栏中。

    0 回复  |  直到 1 年前
        1
  •  0
  •   starball Martin Jorgensen    1 年前

    我不知道vscode中是否有任何输入框,你可以在其中打开它、聚焦它,然后向其中添加文本。你可能首先需要用命令的参数打开它。因此,每种类型的输入框的参数都不同。

    具体来说,对于查找小部件,您可以使用以下内容:

        "command": "editor.actions.findWithArgs",
        "args": {
          // "findInSelection": true,      // doesn't work
          "matchCase": false,              // should be isCaseSensitive
          // "matchCaseOverride": 0,       // appears to not be implemented
          // "preserveCase": true,        
          // "preserveCaseOverride": 0,    // appears to not be implemented
          "isRegex": true,
          // "regexOverride": 1,           // appears to not be implemented
          "searchString": "some queryString",
          "replaceString": "a replacement string"
          // "wholeWord": true,            // should be matchWholeWord
          // "wholeWordOverride": 0        // appears to not be implemented
        }
    

    对于跨文件搜索,可以使用以下参数:

        "command": "workbench.action.findInFiles",
        "args": {
          "query": "(enum|struct|fn|trait|impl(<.*>)?|type) ",
          "isRegex": true,
          "replace": "$1",
          // "triggerSearch": true,          // seems to be the default
          "filesToInclude": "src, include",  // no variables in findInFiles
          // "preserveCase": true,
          // "useExcludeSettingsAndIgnoreFiles": false,
          // "isCaseSensitive": true,
          // "matchWholeWord": true,
          // "filesToExclude": ""
        }
    

    您可以将这些命令与它们一起使用 args 在宏扩展或内置 runCommands .

    推荐文章