Skip to content

Commit f8a1694

Browse files
committed
Add setting to determine console focus behavior on script execution
This change adds a new setting that controls whether focus changes to the integrated console when scripts are executed or debugged: - `powershell.integratedConsole.focusConsoleOnExecute` When true, it causes the focus to get set to the console on any script execution. It is set to true by default to ensure that screen readers pick up the execution output once it starts. Resolves #588.
1 parent 011e80f commit f8a1694

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@
403403
"type": "boolean",
404404
"default": true,
405405
"description": "If true, causes the integrated console to be shown automatically when the PowerShell extension is initialized."
406+
},
407+
"powershell.integratedConsole.focusConsoleOnExecute": {
408+
"type": "boolean",
409+
"default": true,
410+
"description": "If true, causes the integrated console to be focused when a script selection is run or a script file is debugged."
406411
}
407412
}
408413
}

src/features/Console.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export class ConsoleFeature implements IFeature {
217217
});
218218

219219
// Show the integrated console if it isn't already visible
220-
vscode.commands.executeCommand("PowerShell.ShowSessionConsole");
220+
vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
221221
})
222222
];
223223
}

src/features/DebugSession.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class DebugSessionFeature implements IFeature {
6363

6464
// Create or show the interactive console
6565
// TODO #367: Check if "newSession" mode is configured
66-
vscode.commands.executeCommand('PowerShell.ShowSessionConsole');
66+
vscode.commands.executeCommand('PowerShell.ShowSessionConsole', true);
6767

6868
vscode.commands.executeCommand('vscode.startDebug', config);
6969
}

src/session.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export class SessionManager {
6464
private hostVersion: string;
6565
private isWindowsOS: boolean;
6666
private sessionStatus: SessionStatus;
67+
private focusConsoleOnExecute: boolean;
6768
private statusBarItem: vscode.StatusBarItem;
6869
private sessionConfiguration: SessionConfiguration;
6970
private versionDetails: PowerShellVersionDetails;
@@ -105,6 +106,8 @@ export class SessionManager {
105106
this.sessionSettings = Settings.load(utils.PowerShellLanguageId);
106107
this.log.startNewLog(this.sessionSettings.developer.editorServicesLogLevel);
107108

109+
this.focusConsoleOnExecute = this.sessionSettings.integratedConsole.focusConsoleOnExecute;
110+
108111
this.createStatusBarItem();
109112

110113
this.sessionConfiguration = this.resolveSessionConfiguration(sessionConfig);
@@ -206,6 +209,8 @@ export class SessionManager {
206209
private onConfigurationUpdated() {
207210
var settings = Settings.load(utils.PowerShellLanguageId);
208211

212+
this.focusConsoleOnExecute = settings.integratedConsole.focusConsoleOnExecute;
213+
209214
// Detect any setting changes that would affect the session
210215
if (settings.useX86Host !== this.sessionSettings.useX86Host ||
211216
settings.developer.powerShellExePath.toLowerCase() !== this.sessionSettings.developer.powerShellExePath.toLowerCase() ||
@@ -245,7 +250,7 @@ export class SessionManager {
245250
vscode.commands.registerCommand('PowerShell.RestartSession', () => { this.restartSession(); }),
246251
vscode.commands.registerCommand(this.ShowSessionMenuCommandName, () => { this.showSessionMenu(); }),
247252
vscode.workspace.onDidChangeConfiguration(() => this.onConfigurationUpdated()),
248-
vscode.commands.registerCommand('PowerShell.ShowSessionConsole', () => { this.showSessionConsole(); })
253+
vscode.commands.registerCommand('PowerShell.ShowSessionConsole', (isExecute?: boolean) => { this.showSessionConsole(isExecute); })
249254
]
250255
}
251256

@@ -629,9 +634,10 @@ export class SessionManager {
629634
return resolvedPath;
630635
}
631636

632-
private showSessionConsole() {
637+
private showSessionConsole(isExecute?: boolean) {
633638
if (this.consoleTerminal) {
634-
this.consoleTerminal.show(true);
639+
this.consoleTerminal.show(
640+
isExecute && !this.focusConsoleOnExecute);
635641
}
636642
}
637643

src/settings.ts

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface ISettings {
4343

4444
export interface IIntegratedConsoleSettings {
4545
showOnStartup?: boolean;
46+
focusConsoleOnExecute?: boolean;
4647
}
4748

4849
export function load(myPluginId: string): ISettings {
@@ -75,6 +76,7 @@ export function load(myPluginId: string): ISettings {
7576

7677
let defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = {
7778
showOnStartup: true,
79+
focusConsoleOnExecute: true
7880
};
7981

8082
return {

0 commit comments

Comments
 (0)