宏扩展无法同步运行命令

问题描述 投票:0回答:1

我想做一个快捷方式,可以将当前日期插入VScode中该行的72位。我先将光标移到Pos 72,然后使用扩展名获取当前日期。但是,自定义扩展名不等待游标移动,并且日期显示在当前位置。宏运行时似乎发生了异步。这是我的代码

"addDate": [
  "cursorLineEnd",
  {"command": "type", "args": {"text": "                                                                        "}},
  "cursorLineStart",
  {"command": "cursorMove", "args": {"to": "right", "by": "character", "value": 72}},
  {"command": "type", "args": {"text": "AD"}},
  "editor.action.trimTrailingWhitespace",
  {"command": "insertDateString.insertDate"},
]

{"command": "insertDateString.insertDate"},没有等待cursorMove完成并直接工作。有没有什么方法可以让PG按顺序运行“ promise ... then”或优先级设置?谢谢

json vscode-settings
1个回答
0
投票

我建议使用宏命令multi-command。它可以正确处理同步命令。因此,使用多命令将其放入您的settings.josn:

 "multiCommand.commands": [

   {
      "command": "multiCommand.addDate",
      "sequence": [
        "cursorLineEnd",
        {
          "command": "type", 
          "args": {   "text": "                                                                        "
          }
        },
        "cursorLineStart",
        {"command": "cursorMove", "args": {"to": "right", "by": "character", "value": 72}},
        {"command": "type", "args": {"text": "AD"}},
        "editor.action.trimTrailingWhitespace",
        {"command": "insertDateString.insertDate"}
      ]
    }
  ]

然后您的键绑定如下所示:

 {
    "key": "alt+d",                  // whatever you choose
    "command": "extension.multiCommand.execute",
    "args": { "command": "multiCommand.addDate" },
    // "when": "editorTextFocus"
  },

并且它按预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.