You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
forceClearScrollbackBuffer conflicts with focusConsoleOnExecute #2313
Adding the following setting "powershell.integratedConsole.forceClearScrollbackBuffer":true causes the setting "powershell.integratedConsole.focusConsoleOnExecute": false to be ignored.
This means that the focus shifts to the terminal instead of staying inside the code window
System Details
System Details Output
Issue Description
I am experiencing a problem with keeping the focus on the code window instead of the terminal windows
Expected Behaviour
When i run/execute powershell code i expect the focus to stay in the code windows when this setting is added : "powershell.integratedConsole.focusConsoleOnExecute": false
Actual Behaviour
The setting "powershell.integratedConsole.focusConsoleOnExecute": false is being ignored when i added "powershell.integratedConsole.forceClearScrollbackBuffer": true,, so everytime i execute code my cursor/marker is focused to the terminal windows.
Attached Logs
Follow the instructions in the troubleshooting docs
about capturing and sending logs.
I don't think this was the same thing I was seeing, though my issue did also concern how the console focusing logic worked (it was revealing + focusing the wrong console when I had it hiding the integrated console by default and also running debug sessions in new consoles every time, forget the exact setting names but yeah).
Picking this back up — the root cause is on the PowerShellEditorServices side, so I'm transferring this issue there to fix it. Summary of the investigation:
Why it happens
forceClearScrollbackBuffer exists because PSES's Clear-Host calls [Console]::Clear(), which clears the terminal viewport but not xterm.js's scrollback. To wipe scrollback, PSES round-trips an editor/clearTerminal notification to the extension, which runs workbench.action.terminal.clear. That workbench command always focuses the terminal — so every Clear-Host steals focus from the editor, even when focusConsoleOnExecute: false.
Why we can't fix it cleanly in the extension
The obvious client-side fix — "after clearing, restore focus to the editor only if an editor was focused" — isn't possible, because extension code can't read that condition:
window.activeTextEditor is "the one that currently has focus or, when none has focus, the one that changed input most recently" — so it stays defined when the terminal is focused; it can't distinguish editor-focused from terminal-focused.
TerminalState exposes only isInteractedWith + shell — no focus flag (and isInteractedWith is sticky).
window.activeTerminal is the active terminal, not the focused one.
There's no Terminal.clear() and no focus-free clear command; only workbench.action.terminal.clear, which focuses.
So the only client-side options are: restore focus unconditionally (regresses interactive Clear-Host/cls — typing it in the terminal now bounces focus to the editor) or do nothing (original bug). PR PowerShell/vscode-powershell#5519 took the unconditional route; that regression is why it's being closed.
The fix (in PSES)
Have PSES write the xterm "Erase Saved Lines" sequence (CSI 3 J = ESC[3J, i.e. \x1b[3J) directly to its own console output as part of Clear-Host, instead of round-tripping editor/clearTerminal. VS Code's integrated terminal is always xterm.js, which honors ESC[3J; the scrollback clears in-band with no focus change at all, in both the run-from-editor and the typed-in-terminal cases. No focus detection needed.
This is safe because the extension↔PSES LSP runs over a named pipe/socket (not stdio), so PSES stdout is the terminal output and is separate from the LSP channel.
Concrete plan:
Map integratedConsole.forceClearScrollbackBuffer onto LanguageServerSettings (the extension already syncs the whole powershell config section via didChangeConfiguration).
In Clear-Host / EditorOperationsService.ClearTerminal(), when that setting is true, write ESC[3J to the host output instead of sending editor/clearTerminal.
In vscode-powershell (follow-up): remove the editor/clearTerminal handler once PSES lands; keep the forceClearScrollbackBuffer setting (now consumed server-side).
Activity
SydneyhSmith commentedon Jul 28, 2020
I am thinking Rain Sallow (/u/ta11ow) (@vexx32) was having this issue, but I cant seem to find the bug
vexx32 commentedon Jul 28, 2020
I don't think this was the same thing I was seeing, though my issue did also concern how the console focusing logic worked (it was revealing + focusing the wrong console when I had it hiding the integrated console by default and also running debug sessions in new consoles every time, forget the exact setting names but yeah).
andyleejordan commentedon Jun 16, 2026
Root cause and fix plan
Picking this back up — the root cause is on the PowerShellEditorServices side, so I'm transferring this issue there to fix it. Summary of the investigation:
Why it happens
forceClearScrollbackBufferexists because PSES'sClear-Hostcalls[Console]::Clear(), which clears the terminal viewport but not xterm.js's scrollback. To wipe scrollback, PSES round-trips aneditor/clearTerminalnotification to the extension, which runsworkbench.action.terminal.clear. That workbench command always focuses the terminal — so everyClear-Hoststeals focus from the editor, even whenfocusConsoleOnExecute: false.Why we can't fix it cleanly in the extension
The obvious client-side fix — "after clearing, restore focus to the editor only if an editor was focused" — isn't possible, because extension code can't read that condition:
window.activeTextEditoris "the one that currently has focus or, when none has focus, the one that changed input most recently" — so it stays defined when the terminal is focused; it can't distinguish editor-focused from terminal-focused.TerminalStateexposes onlyisInteractedWith+shell— no focus flag (andisInteractedWithis sticky).window.activeTerminalis the active terminal, not the focused one.terminalFocus/editorTextFocusarewhen-clause context keys only; there's no API to read a context key from code (CTRL+p stopped working microsoft/vscode#72647).Terminal.clear()and no focus-free clear command; onlyworkbench.action.terminal.clear, which focuses.So the only client-side options are: restore focus unconditionally (regresses interactive
Clear-Host/cls— typing it in the terminal now bounces focus to the editor) or do nothing (original bug). PR PowerShell/vscode-powershell#5519 took the unconditional route; that regression is why it's being closed.The fix (in PSES)
Have PSES write the xterm "Erase Saved Lines" sequence (
CSI 3 J=ESC[3J, i.e.\x1b[3J) directly to its own console output as part ofClear-Host, instead of round-trippingeditor/clearTerminal. VS Code's integrated terminal is always xterm.js, which honorsESC[3J; the scrollback clears in-band with no focus change at all, in both the run-from-editor and the typed-in-terminal cases. No focus detection needed.This is safe because the extension↔PSES LSP runs over a named pipe/socket (not stdio), so PSES stdout is the terminal output and is separate from the LSP channel.
Concrete plan:
integratedConsole.forceClearScrollbackBufferontoLanguageServerSettings(the extension already syncs the wholepowershellconfig section viadidChangeConfiguration).Clear-Host/EditorOperationsService.ClearTerminal(), when that setting is true, writeESC[3Jto the host output instead of sendingeditor/clearTerminal.editor/clearTerminalhandler once PSES lands; keep theforceClearScrollbackBuffersetting (now consumed server-side).Investigation drafted by Copilot for Andy Jordan (@andyleejordan).