[英]How to return focus to editor in VS Code macro sending Python text to Debug Console?
I have tried to key-bind a macro to send python text to the Debug Console and return focus to the editor in Visual Studio Code.我试图键绑定一个宏以将 python 文本发送到调试控制台并将焦点返回到 Visual Studio Code 中的编辑器。 This is what I have tried:
这是我试过的:
settings.json
: settings.json
:
{
"macros": {
"selectionToReplAndReturnToEditor": [
"editor.debug.action.selectionToRepl",
"workbench.action.focusActiveEditorGroup"
]
}
}
keybindings.json
: 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"
}
]
Now, Ctrl + Enter does execute text in the Debug Console, but does not return focus to the editor.现在, Ctrl + Enter会在调试控制台中执行文本,但不会将焦点返回到编辑器。 Ctrl + Enter followed by Alt + F9 does that, but of course, I would like to bind a single key.
Ctrl + Enter后跟Alt + F9可以做到这一点,但当然,我想绑定一个键。 Am I doing something wrong?
难道我做错了什么? Do I need some wait time in the macro?
我需要在宏中等待一些时间吗? How can I achieve that?
我怎样才能做到这一点?
@bers answer is a God-send. @bers 的回答是天赐之物。 here is the full solution.
这是完整的解决方案。
There are a few things that we need to do here:我们需要在这里做几件事:
editor.debug.action.selectionToRepl
.editor.debug.action.selectionToRepl
的操作。 in keybindings.json
在
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"
},
In settings.json
在
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",
]
},
]
This works, using a different extension:这有效,使用不同的扩展名:
"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",
]
},
}
I have tried to key-bind a macro to send python text to the Debug Console and return focus to the editor in Visual Studio Code.我试图键绑定一个宏以将 python 文本发送到调试控制台并将焦点返回到 Visual Studio Code 中的编辑器。 This is what I have tried:
这是我尝试过的:
settings.json
: settings.json
:
{
"macros": {
"selectionToReplAndReturnToEditor": [
"editor.debug.action.selectionToRepl",
"workbench.action.focusActiveEditorGroup"
]
}
}
keybindings.json
: 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"
}
]
Now, Ctrl + Enter does execute text in the Debug Console, but does not return focus to the editor.现在, Ctrl + Enter确实会在调试控制台中执行文本,但不会将焦点返回到编辑器。 Ctrl + Enter followed by Alt + F9 does that, but of course, I would like to bind a single key.
Ctrl + Enter后跟Alt + F9 可以做到这一点,但当然,我想绑定一个键。 Am I doing something wrong?
难道我做错了什么? Do I need some wait time in the macro?
我需要在宏中等待一些时间吗? How can I achieve that?
我怎样才能做到这一点?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.