Skip to content

Commit

Permalink
Merge pull request #197258 from microsoft/merogge/focus-view
Browse files Browse the repository at this point in the history
add setting to focus accessible view on command execution
  • Loading branch information
meganrogge committed Nov 3, 2023
2 parents a2516df + 625fb19 commit e550098
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const enum TerminalSettingId {
IgnoreBracketedPasteMode = 'terminal.integrated.ignoreBracketedPasteMode',
FocusAfterRun = 'terminal.integrated.focusAfterRun',
AccessibleViewPreserveCursorPosition = 'terminal.integrated.accessibleViewPreserveCursorPosition',
AccessibleViewFocusOnCommandExecution = 'terminal.integrated.accessibleViewFocusOnCommandExecution',

// Debug settings that are hidden from user

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,12 @@ const terminalConfiguration: IConfigurationNode = {
markdownDescription: localize('terminal.integrated.accessibleViewPreserveCursorPosition', "Preserve the cursor position on reopen of the terminal's accessible view rather than setting it to the bottom of the buffer."),
type: 'boolean',
default: false
}
},
[TerminalSettingId.AccessibleViewFocusOnCommandExecution]: {
markdownDescription: localize('terminal.integrated.accessibleViewFocusOnCommandExecution', "Focus the terminal accessible view when a command is executed."),
type: 'boolean',
default: false
},
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { localize } from 'vs/nls';
import { CONTEXT_ACCESSIBILITY_MODE_ENABLED } from 'vs/platform/accessibility/common/accessibility';
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
Expand Down Expand Up @@ -66,6 +66,8 @@ export class TerminalAccessibleViewContribution extends Disposable implements IT
private _bufferTracker: BufferContentTracker | undefined;
private _bufferProvider: TerminalAccessibleBufferProvider | undefined;
private _xterm: Pick<IXtermTerminal, 'shellIntegration' | 'getFont'> & { raw: Terminal } | undefined;
private _onCommandExecutedShowListener: MutableDisposable<IDisposable> = new MutableDisposable();

constructor(
private readonly _instance: ITerminalInstance,
processManager: ITerminalProcessManager,
Expand All @@ -91,7 +93,18 @@ export class TerminalAccessibleViewContribution extends Disposable implements IT
this.show();
}
}));
this._register(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(TerminalSettingId.AccessibleViewFocusOnCommandExecution)) {
this._updateCommandExecutedListener();
}
}));
this._register(this._instance.capabilities.onDidAddCapability(e => {
if (e.capability.type === TerminalCapability.CommandDetection) {
this._updateCommandExecutedListener();
}
}));
}

xtermReady(xterm: IXtermTerminal & { raw: Terminal }): void {
const addon = this._instantiationService.createInstance(TextAreaSyncAddon, this._instance.capabilities);
xterm.raw.loadAddon(addon);
Expand All @@ -111,6 +124,25 @@ export class TerminalAccessibleViewContribution extends Disposable implements IT
}));
}

private _updateCommandExecutedListener(): void {
if (!this._instance.capabilities.has(TerminalCapability.CommandDetection)) {
return;
}
if (!this._configurationService.getValue(TerminalSettingId.AccessibleViewFocusOnCommandExecution)) {
this._onCommandExecutedShowListener.clear();
return;
} else if (this._onCommandExecutedShowListener.value) {
return;
}

const capability = this._instance.capabilities.get(TerminalCapability.CommandDetection)!;
this._onCommandExecutedShowListener.value = this._register(capability.onCommandExecuted(() => {
if (this._instance.hasFocus) {
this.show();
}
}));
}

private _isTerminalAccessibleViewOpen(): boolean {
return accessibleViewCurrentProviderId.getValue(this._contextKeyService) === AccessibleViewProviderId.Terminal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AccessibilityCommandId } from 'vs/workbench/contrib/accessibility/commo
import { ITerminalInstance, IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal';
import { TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
import type { Terminal } from '@xterm/xterm';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';

export const enum ClassName {
Active = 'active',
Expand Down Expand Up @@ -49,7 +50,8 @@ export class TerminalAccessibilityHelpProvider extends Disposable implements IAc
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@ICommandService private readonly _commandService: ICommandService,
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService,
@IConfigurationService private readonly _configurationService: IConfigurationService
) {
super();
this._hasShellIntegration = _xterm.shellIntegration.status === ShellIntegrationStatus.VSCode;
Expand Down Expand Up @@ -77,6 +79,9 @@ export class TerminalAccessibilityHelpProvider extends Disposable implements IAc
const content = [];
content.push(this._descriptionForCommand(TerminalCommandId.FocusAccessibleBuffer, localize('focusAccessibleTerminalView', 'The Focus Accessible Terminal View ({0}) command enables screen readers to read terminal contents.'), localize('focusAccessibleTerminalViewNoKb', 'The Focus Terminal Accessible View command enables screen readers to read terminal contents and is currently not triggerable by a keybinding.')));
content.push(localize('preserveCursor', 'Customize the behavior of the cursor when toggling between the terminal and accessible view with `terminal.integrated.accessibleViewPreserveCursorPosition.`'));
if (!this._configurationService.getValue(TerminalSettingId.AccessibleViewFocusOnCommandExecution)) {
content.push(localize('focusViewOnExecution', 'Enable `terminal.integrated.accessibleViewFocusOnCommandExecution` to automatically focus the terminal accessible view when a command is executed in the terminal.'));
}
if (this._instance.shellType === WindowsShellType.CommandPrompt) {
content.push(localize('commandPromptMigration', "Consider using powershell instead of command prompt for an improved experience"));
}
Expand Down

0 comments on commit e550098

Please sign in to comment.