ber*_*ers 2 python macros visual-studio-code
我尝试按键绑定宏以将 python 文本发送到调试控制台并将焦点返回到 Visual Studio Code 中的编辑器。这是我尝试过的:
settings.json:
{
"macros": {
"selectionToReplAndReturnToEditor": [
"editor.debug.action.selectionToRepl",
"workbench.action.focusActiveEditorGroup"
]
}
}
Run Code Online (Sandbox Code Playgroud)
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"
}
]
Run Code Online (Sandbox Code Playgroud)
现在,Ctrl+Enter确实在调试控制台中执行文本,但不会将焦点返回到编辑器。Ctrl+Enter后面跟着Alt+F9可以做到这一点,但当然,我想绑定一个键。难道我做错了什么?我需要在宏中等待一些时间吗?我怎样才能做到这一点?
@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": "extension.multiCommand.execute",
"args": { "command": "multiCommand.selectionToReplAndReturnToEditor" },
"when": "editorTextFocus && editorHasSelection && editorLangId == 'python' && inDebugMode"
},
Run Code Online (Sandbox Code Playgroud)
在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",
]
},
]
Run Code Online (Sandbox Code Playgroud)