Skip to content

Commit dd858b5

Browse files
Document why clearTerminal can't restore prior focus
The focus-restore is best-effort: `workbench.action.terminal.clear` always focuses the terminal, and VS Code's stable API exposes no way to learn what was focused before the clear (`TerminalState` has no focus flag, and `activeTextEditor` does not go `undefined` when the terminal is focused). So we can't perfectly return focus to wherever it was. Spell out the resulting caveat in a comment: running `Clear-Host` directly in the console while `focusConsoleOnExecute` is `false` will also move focus to the editor. That edge case is consistent with the user's stated preference to keep focus in the editor, and fixing it properly isn't possible without a focus-state signal the API doesn't provide. Drafted by Copilot (Claude Opus 4.8). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ce7f498 commit dd858b5

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎src/features/ExtensionCommands.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,13 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
338338

339339
await vscode.commands.executeCommand("workbench.action.terminal.clear");
340340

341-
// Clearing the terminal focuses it, but if the user has asked us not to
342-
// focus the console on execute, then we restore focus to the editor.
341+
// Clearing the terminal also focuses it, and VS Code exposes no way to
342+
// learn what was focused beforehand (there's no terminal focus state,
343+
// and `activeTextEditor` doesn't go undefined when the terminal is
344+
// focused). So when the user has opted out of focusing the console on
345+
// execute, we best-effort restore focus to the editor. The caveat is
346+
// that running `Clear-Host` directly in the console also moves focus to
347+
// the editor under this setting.
343348
const focusConsoleOnExecute = vscode.workspace
344349
.getConfiguration("powershell.integratedConsole")
345350
.get<boolean>("focusConsoleOnExecute", true);

0 commit comments

Comments
 (0)