我尝试对宏进行键绑定以将Python文本发送到调试控制台,并将焦点返回到Visual Studio Code中的编辑器。这就是我的尝试:
settings.json
:
{
"macros": {
"selectionToReplAndReturnToEditor": [
"editor.debug.action.selectionToRepl",
"workbench.action.focusActiveEditorGroup"
]
}
}
keybindings.json
:
[
{
"key": "alt+f9",
"command": "workbench.action.focusActiveEditorGroup",
},
{
"key": "alt+f10",
"command": "workbench.debug.action.focusRepl",
},
{
"key": "ctrl+enter",
"command": "macros.selectionToReplAndReturnToEditor",
"when": "editorTextFocus && editorHasSelection && editorLangId == 'python' && inDebugMode"
}
]
现在, Ctrl + Enter 会在调试控制台中执行文本,但不会将焦点返回到编辑器。 Ctrl + 输入后跟 Alt + F9 这样做,但当然,我想绑定一个键。难道我做错了什么?我需要在宏中等待一段时间吗?我怎样才能做到这一点?
答案 0 :(得分:0)
这可以使用其他扩展名进行工作:
"multiCommand.commands": [ // requires vscode:extension/ryuta46.multi-command
{ // ctrl+enter, editorTextFocus && editorHasSelection && editorLangId == 'python' && inDebugMode
"command": "multiCommand.selectionToReplAndReturnToEditor",
"sequence": [
"editor.debug.action.selectionToRepl",
"workbench.action.focusActiveEditorGroup",
]
},
}
答案 1 :(得分:0)
谢谢!它对我来说并不完全有效。 我猜在焦点文本编辑器中选择的代码和实际光标之间存在差异。 我应该问这个。
答案 2 :(得分:0)
@bers的答案是天赐之物。这是完整的解决方案。
在这里我们需要做一些事情:
editor.debug.action.selectionToRepl
的操作。在keybindings.json
{
"key": "cmd+enter",
"command": "workbench.action.terminal.runSelectedText",
"when": "editorHasSelection && editorTextFocus && !inDebugMode"
},
{
"key": "cmd+enter",
// This needs to be the command you define above.
"command": "multiCommand.selectionToReplAndReturnToEditor",
"when": "editorTextFocus && editorHasSelection && editorLangId == 'python' && inDebugMode"
}
在settings.json
"multiCommand.commands": [ // requires vscode:extension/ryuta46.multi-command
{ // ctrl+enter, editorTextFocus && editorHasSelection && editorLangId == 'python' && inDebugMode
"command": "multiCommand.selectionToReplAndReturnToEditor",
"sequence": [
"editor.debug.action.selectionToRepl",
"workbench.action.focusActiveEditorGroup",
]
},
]