英文:
Why does VS Code 1.75 move focus to the terminal when running selected text?
问题
A few days ago VS Code recently self-updated to version 1.75.0 and the functionality of runSelectedText
seems to have changed.
Previously, as I recall, if this command was called, highlighted text would be run in terminal without the cursor moving. Now, if this command is run, the cursor jumps from the editor to the terminal. I would like to either (i) change a setting somewhere (if it exists) so that this command doesn't jump to the terminal, or, (ii) work out a way of returning the cursor to the editor (e.g., with a macro).
I previously had this as part of a macro to highlight the current line (using the macros extension). I selected the current line, ran the text in terminal, then cancelled the selection.
So my main approach so far has been a number of variations on the workbench.action.focusActiveEditorGroup
command to include this within a macro.
As a MWE, the following macro I have included in settings.json:
"macros": {
"runAndReturn": [
"workbench.action.terminal.runSelectedText",
"workbench.action.focusActiveEditorGroup" // <--- this doesn't work/do anything
],
},
For me, when I run this macro, it executes the current line as expected, but the cursor moves to the terminal and doesn't return back to the editor.
英文:
A few days ago VS Code recently self-updated to version 1.75.0 and the functionality of runSelectedText
seems to have changed.
Previously, as I recall, if this command was called, highlighted text would be run in terminal without the cursor moving. Now, if this command is run, the cursor jumps from the editor to the terminal. I would like to either (i) change a setting somewhere (if it exists) so that this command doesn't jump to the terminal, or, (ii) work out a way of returning the cursor to the editor (e.g., with a macro).
I previously had this as part of a macro to highlight the current line (using the macros extension). I selected the current line, ran the text in terminal, then cancelled the selection.
So my main approach so far has been a number of variations on the workbench.action.focusActiveEditorGroup
command to include this within a macro.
As a MWE, the following macro I have included in settings.json:
"macros": {
"runAndReturn": [
"workbench.action.terminal.runSelectedText",
"workbench.action.focusActiveEditorGroup" // <--- this doesn't work/do anything
],
},
For me, when I run this macro, it executes the current line as expected, but the cursor moves to the terminal and doesn't return back to the editor.
答案1
得分: 2
这个问题已经在这里报告了:https://github.com/microsoft/vscode/issues/173247
它是由这个提交引起的:https://github.com/microsoft/vscode/commit/305de596d216fb925e3cc298c0b67ad99ad0b6c2
问题已在此处修复:https://github.com/microsoft/vscode/pull/173573
请查看第一个链接以获取人们找到的一些解决方法,在等待修复版本发布时可以使用:
-
使用<kbd>ctrl</kbd>+<kbd>1</kbd>来聚焦到第一个编辑组(或任何您想要聚焦的编辑组的编号)。
-
由 anderswe 发现:使用 the multi-command extension 并使用以下配置:
>json > { > "key": "cmd+enter", // or ctrl+enter > "command": "extension.multiCommand.execute", > "args": { > "sequence": [ > "workbench.action.terminal.runSelectedText", // 运行行 > "workbench.action.focusActiveEditorGroup", // 将焦点切回编辑器 > "cursorDown" // 跳转到下一行,以便连续使用 cmd+enter > ] > }, > "when": "editorTextFocus" > } >
-
您可以使用<kbd>ctrl</kbd>+<kbd>j</kbd>来切换集成终端视图的可见性。
请注意,自 VS Code 1.82 起,您可以通过设置 terminal.integrated.focusAfterRun
来控制终端是否会被聚焦。
英文:
This issue was reported here: https://github.com/microsoft/vscode/issues/173247
It was caused here https://github.com/microsoft/vscode/commit/305de596d216fb925e3cc298c0b67ad99ad0b6c2
It was fixed here: https://github.com/microsoft/vscode/pull/173573
See the first link for some workarounds people found, which you can use while waiting for a version with the fix to be released:
-
Using <kbd>ctrl</kbd>+<kbd>1</kbd> to focus the first editor group (or the number of whichever editor group you want to focus).
-
Found by anderswe: Using the multi-command extension with the following:
>json
> {
> "key": "cmd+enter", // or ctrl+enter
> "command": "extension.multiCommand.execute",
> "args": {
> "sequence": [
> "workbench.action.terminal.runSelectedText", // run line
> "workbench.action.focusActiveEditorGroup", // shift focus back to editor
> "cursorDown" // jump to next line so you can spam cmd+enter
> ]
> },
> "when": "editorTextFocus"
> }
> -
You can use <kbd>ctrl</kbd>+<kbd>j</kbd> to toggle the visibility of the integrated terminal view.
Note that since VS Code 1.82, you can control whether the terminal will be focused using the terminal.integrated.focusAfterRun
setting.
答案2
得分: 0
在vscode v1.82中,有一个新的设置,用于控制在运行workbench.action.terminal.runSelectedText
命令后,是切换焦点到终端、可访问的缓冲区,还是保持在编辑器中。详见GitHub拉取请求:添加focusAfterRun设置。
该设置是:
Terminal > Integrated: Focus After Run
> "控制在运行 `Terminal: Run Selected Text In Active Terminal` 后,终端、可访问的缓冲区或都不会被
> 聚焦。"
选项有:
none
(默认):焦点保持在编辑器中。terminal
:始终将焦点聚焦在终端上。accessible-buffer
:始终将焦点聚焦在可访问的缓冲区上。
英文:
There is a new setting in vscode v1.82 that governs whether to switch focus to the terminal, accessible buffer or remain in the editor after running the workbench.action.terminal.runSelectedText
command. See GH Pull Request: add focusAfterRun setting.
The setting is
Terminal > Integrated: Focus After Run
> "Controls whether the terminal, accessible buffer, or neither will be
> focused after `Terminal: Run Selected Text In Active Terminal` has
> been run."
Options are:
none // the default, focus remains in editor
terminal // "Always focus the terminal."
accessible-buffer // "Always focus the accessible buffer."
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论