宏扩展没有 运行 同步命令
macro extension does not run commands synchronously
我想制作一个快捷方式,可以在 VScode 行的第 72 位插入当前日期。
我先让 Cursor 转到 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完成直接工作。
有没有什么办法像"promise...then"或者优先级设置让PG按顺序运行?
谢谢
我建议使用宏指令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"
},
它按预期工作。
我想制作一个快捷方式,可以在 VScode 行的第 72 位插入当前日期。 我先让 Cursor 转到 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完成直接工作。
有没有什么办法像"promise...then"或者优先级设置让PG按顺序运行?
谢谢
我建议使用宏指令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"
},
它按预期工作。