为什么VS Code 1.75在运行选定的文本时将焦点移至终端?

huangapple go评论55阅读模式
英文:

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:

&quot;macros&quot;: {
        &quot;runAndReturn&quot;: [ 
           &quot;workbench.action.terminal.runSelectedText&quot;,
           &quot;workbench.action.focusActiveEditorGroup&quot; // &lt;--- this doesn&#39;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 &gt; { &gt; "key": "cmd+enter", // or ctrl+enter &gt; "command": "extension.multiCommand.execute", &gt; "args": { &gt; "sequence": [ &gt; "workbench.action.terminal.runSelectedText", // 运行行 &gt; "workbench.action.focusActiveEditorGroup", // 将焦点切回编辑器 &gt; "cursorDown" // 跳转到下一行,以便连续使用 cmd+enter &gt; ] &gt; }, &gt; "when": "editorTextFocus" &gt; } &gt;

  • 您可以使用<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
    &gt; {
    &gt; &quot;key&quot;: &quot;cmd+enter&quot;, // or ctrl+enter
    &gt; &quot;command&quot;: &quot;extension.multiCommand.execute&quot;,
    &gt; &quot;args&quot;: {
    &gt; &quot;sequence&quot;: [
    &gt; &quot;workbench.action.terminal.runSelectedText&quot;, // run line
    &gt; &quot;workbench.action.focusActiveEditorGroup&quot;, // shift focus back to editor
    &gt; &quot;cursorDown&quot; // jump to next line so you can spam cmd+enter
    &gt; ]
    &gt; },
    &gt; &quot;when&quot;: &quot;editorTextFocus&quot;
    &gt; }
    &gt;

  • 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 &gt; Integrated: Focus After Run

&gt; &quot;控制在运行 `Terminal: Run Selected Text In Active Terminal` 后,终端、可访问的缓冲区或都不会被
&gt; 聚焦。&quot;

选项有:

  • 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 &gt; Integrated: Focus After Run

&gt; &quot;Controls whether the terminal, accessible buffer, or neither will be
&gt; focused after `Terminal: Run Selected Text In Active Terminal` has
&gt; been run.&quot;

Options are:

none                // the default, focus remains in editor
terminal            // &quot;Always focus the terminal.&quot;
accessible-buffer   // &quot;Always focus the accessible buffer.&quot;

huangapple
  • 本文由 发表于 2023年2月8日 18:08:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75384195.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定