Skip to content

Commit fd02201

Browse files
authored
Merge pull request #287015 from microsoft/tyriar/286896
disable win32 input mode by default, add exp, advanced
2 parents 187943b + 9072d9e commit fd02201

File tree

6 files changed

+52
-4
lines changed

6 files changed

+52
-4
lines changed

src/vs/platform/terminal/common/terminal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export const enum TerminalSettingId {
121121
FontLigaturesFeatureSettings = 'terminal.integrated.fontLigatures.featureSettings',
122122
FontLigaturesFallbackLigatures = 'terminal.integrated.fontLigatures.fallbackLigatures',
123123
EnableKittyKeyboardProtocol = 'terminal.integrated.enableKittyKeyboardProtocol',
124+
EnableWin32InputMode = 'terminal.integrated.enableWin32InputMode',
124125

125126
// Developer/debug settings
126127

src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class XtermTerminal extends Disposable implements IXtermTerminal, IDetach
245245
rescaleOverlappingGlyphs: config.rescaleOverlappingGlyphs,
246246
vtExtensions: {
247247
kittyKeyboard: config.enableKittyKeyboardProtocol,
248-
win32InputMode: true,
248+
win32InputMode: config.enableWin32InputMode,
249249
},
250250
windowOptions: {
251251
getWinSizePixels: true,
@@ -543,7 +543,7 @@ export class XtermTerminal extends Disposable implements IXtermTerminal, IDetach
543543
this.raw.options.rescaleOverlappingGlyphs = config.rescaleOverlappingGlyphs;
544544
this.raw.options.vtExtensions = {
545545
kittyKeyboard: config.enableKittyKeyboardProtocol,
546-
win32InputMode: true,
546+
win32InputMode: config.enableWin32InputMode,
547547
};
548548

549549
this._updateSmoothScrolling();

src/vs/workbench/contrib/terminal/common/scripts/shellIntegration.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,16 @@ function Set-MappedKeyHandler {
250250
}
251251
}
252252

253+
function Set-MappedKeyHandlers {
254+
Set-MappedKeyHandler -Chord Ctrl+Spacebar -Sequence 'F12,a'
255+
Set-MappedKeyHandler -Chord Alt+Spacebar -Sequence 'F12,b'
256+
Set-MappedKeyHandler -Chord Shift+Enter -Sequence 'F12,c'
257+
Set-MappedKeyHandler -Chord Shift+End -Sequence 'F12,d'
258+
}
259+
253260
if ($Global:__VSCodeState.HasPSReadLine) {
261+
Set-MappedKeyHandlers
262+
254263
# Prevent AI-executed commands from polluting shell history
255264
if ($env:VSCODE_PREVENT_SHELL_HISTORY -eq "1") {
256265
Set-PSReadLineOption -AddToHistoryHandler {

src/vs/workbench/contrib/terminal/common/terminal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export interface ITerminalConfiguration {
209209
ignoreBracketedPasteMode: boolean;
210210
rescaleOverlappingGlyphs: boolean;
211211
enableKittyKeyboardProtocol: boolean;
212+
enableWin32InputMode: boolean;
212213
fontLigatures?: {
213214
enabled: boolean;
214215
featureSettings: string;

src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,17 @@ const terminalConfiguration: IStringDictionary<IConfigurationPropertySchema> = {
592592
markdownDescription: localize('terminal.integrated.enableKittyKeyboardProtocol', "Whether to enable the kitty keyboard protocol, which provides more detailed keyboard input reporting to the terminal."),
593593
type: 'boolean',
594594
default: false,
595-
tags: ['experimental'],
595+
tags: ['experimental', 'advanced'],
596+
experiment: {
597+
mode: 'auto'
598+
}
599+
},
600+
[TerminalSettingId.EnableWin32InputMode]: {
601+
restricted: true,
602+
markdownDescription: localize('terminal.integrated.enableWin32InputMode', "Whether to enable the win32 input mode, which provides enhanced keyboard input support on Windows."),
603+
type: 'boolean',
604+
default: false,
605+
tags: ['experimental', 'advanced'],
596606
experiment: {
597607
mode: 'auto'
598608
}

src/vs/workbench/contrib/terminalContrib/sendSequence/browser/terminal.sendSequence.contribution.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ContextKeyExpr, type ContextKeyExpression } from '../../../../../platfo
1313
import type { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
1414
import { KeybindingsRegistry, KeybindingWeight, type IKeybindings } from '../../../../../platform/keybinding/common/keybindingsRegistry.js';
1515
import { IQuickInputService } from '../../../../../platform/quickinput/common/quickInput.js';
16-
import { GeneralShellType, WindowsShellType } from '../../../../../platform/terminal/common/terminal.js';
16+
import { GeneralShellType, TerminalSettingId, WindowsShellType } from '../../../../../platform/terminal/common/terminal.js';
1717
import { IWorkspaceContextService } from '../../../../../platform/workspace/common/workspace.js';
1818
import { IConfigurationResolverService } from '../../../../services/configurationResolver/common/configurationResolver.js';
1919
import { IHistoryService } from '../../../../services/history/common/history.js';
@@ -133,6 +133,33 @@ if (isWindows) {
133133
});
134134
}
135135

136+
// Map certain keybindings in pwsh to unused keys which get handled by PSReadLine handlers in the
137+
// shell integration script. This allows keystrokes that cannot be sent via VT sequences to work.
138+
// See https://github.com/microsoft/terminal/issues/879#issuecomment-497775007
139+
registerSendSequenceKeybinding('\x1b[24~a', { // F12,a -> ctrl+space (MenuComplete)
140+
when: ContextKeyExpr.and(TerminalContextKeys.focus, ContextKeyExpr.equals(TerminalContextKeyStrings.ShellType, GeneralShellType.PowerShell), TerminalContextKeys.terminalShellIntegrationEnabled, ContextKeyExpr.equals(`config.${TerminalSettingId.EnableWin32InputMode}`, true), CONTEXT_ACCESSIBILITY_MODE_ENABLED.negate()),
141+
primary: KeyMod.CtrlCmd | KeyCode.Space,
142+
mac: { primary: KeyMod.WinCtrl | KeyCode.Space }
143+
});
144+
registerSendSequenceKeybinding('\x1b[24~b', { // F12,b -> alt+space (SetMark)
145+
when: ContextKeyExpr.and(TerminalContextKeys.focus, ContextKeyExpr.equals(TerminalContextKeyStrings.ShellType, GeneralShellType.PowerShell), TerminalContextKeys.terminalShellIntegrationEnabled, ContextKeyExpr.equals(`config.${TerminalSettingId.EnableWin32InputMode}`, true), CONTEXT_ACCESSIBILITY_MODE_ENABLED.negate()),
146+
primary: KeyMod.Alt | KeyCode.Space
147+
});
148+
registerSendSequenceKeybinding('\x1b[24~c', { // F12,c -> shift+enter (AddLine)
149+
when: ContextKeyExpr.and(TerminalContextKeys.focus, ContextKeyExpr.equals(TerminalContextKeyStrings.ShellType, GeneralShellType.PowerShell), TerminalContextKeys.terminalShellIntegrationEnabled, ContextKeyExpr.equals(`config.${TerminalSettingId.EnableWin32InputMode}`, true), CONTEXT_ACCESSIBILITY_MODE_ENABLED.negate()),
150+
primary: KeyMod.Shift | KeyCode.Enter
151+
});
152+
registerSendSequenceKeybinding('\x1b[24~d', { // F12,d -> shift+end (SelectLine) - HACK: \x1b[1;2F is supposed to work but it doesn't
153+
when: ContextKeyExpr.and(TerminalContextKeys.focus, ContextKeyExpr.equals(TerminalContextKeyStrings.ShellType, GeneralShellType.PowerShell), TerminalContextKeys.terminalShellIntegrationEnabled, ContextKeyExpr.equals(`config.${TerminalSettingId.EnableWin32InputMode}`, true), CONTEXT_ACCESSIBILITY_MODE_ENABLED.negate()),
154+
mac: { primary: KeyMod.Shift | KeyMod.CtrlCmd | KeyCode.RightArrow }
155+
});
156+
157+
// Always on pwsh keybindings
158+
registerSendSequenceKeybinding('\x1b[1;2H', { // Shift+home
159+
when: ContextKeyExpr.and(TerminalContextKeys.focus, ContextKeyExpr.equals(TerminalContextKeyStrings.ShellType, GeneralShellType.PowerShell), ContextKeyExpr.equals(`config.${TerminalSettingId.EnableWin32InputMode}`, true)),
160+
mac: { primary: KeyMod.Shift | KeyMod.CtrlCmd | KeyCode.LeftArrow }
161+
});
162+
136163
// Map alt+arrow to ctrl+arrow to allow word navigation in most shells to just work with alt. This
137164
// is non-standard behavior, but a lot of terminals act like this (see
138165
// https://github.com/microsoft/vscode/issues/190629). Note that macOS uses different sequences here

0 commit comments

Comments
 (0)