fix(cli): refine platform-specific undo/redo and smart bubbling for WSL (#26202)

This commit is contained in:
Coco Sheng
2026-04-30 10:10:54 -04:00
committed by GitHub
parent 0ccc5ce58f
commit a15568e013
8 changed files with 369 additions and 24 deletions
@@ -108,6 +108,30 @@ describe('keyBindings config', () => {
}
});
it('should have platform-specific UNDO bindings', () => {
const undoBindings = defaultKeyBindingConfig.get(Command.UNDO);
if (process.platform === 'win32') {
expect(undoBindings?.[0].name).toBe('z');
expect(undoBindings?.[0].ctrl).toBe(true);
} else if (process.platform === 'darwin') {
expect(undoBindings?.[0].name).toBe('z');
expect(undoBindings?.[0].cmd).toBe(true);
} else {
expect(undoBindings?.[0].name).toBe('z');
expect(undoBindings?.[0].alt).toBe(true);
// Ensure ctrl+z is also present for smart bubbling
expect(undoBindings?.some((b) => b.name === 'z' && b.ctrl)).toBe(true);
}
});
it('should have platform-specific REDO bindings', () => {
const redoBindings = defaultKeyBindingConfig.get(Command.REDO);
// Ctrl+Shift+Z is now the universal primary to avoid conflict with YOLO (Ctrl+Y)
expect(redoBindings?.[0].name).toBe('z');
expect(redoBindings?.[0].shift).toBe(true);
expect(redoBindings?.[0].ctrl).toBe(true);
});
describe('command metadata', () => {
const commandValues = Object.values(Command);
+32 -9
View File
@@ -312,15 +312,8 @@ export const defaultKeyBindingConfig: KeyBindingConfig = new Map([
Command.DELETE_CHAR_RIGHT,
[new KeyBinding('delete'), new KeyBinding('ctrl+d')],
],
[Command.UNDO, [new KeyBinding('cmd+z'), new KeyBinding('alt+z')]],
[
Command.REDO,
[
new KeyBinding('ctrl+shift+z'),
new KeyBinding('cmd+shift+z'),
new KeyBinding('alt+shift+z'),
],
],
[Command.UNDO, getPlatformUndoBindings(process.platform)],
[Command.REDO, getPlatformRedoBindings(process.platform)],
// Scrolling
[Command.SCROLL_UP, [new KeyBinding('shift+up')]],
@@ -782,3 +775,33 @@ export async function loadCustomKeybindings(): Promise<{
return { config, errors };
}
export function getPlatformUndoBindings(
platform: string,
): readonly KeyBinding[] {
if (platform === 'win32') {
return [new KeyBinding('ctrl+z'), new KeyBinding('alt+z')];
}
if (platform === 'darwin') {
return [new KeyBinding('cmd+z'), new KeyBinding('alt+z')];
}
// Linux / WSL: Promote Alt+Z to avoid Windows interception,
// but keep Ctrl+Z for smart bubbling.
return [
new KeyBinding('alt+z'),
new KeyBinding('cmd+z'),
new KeyBinding('ctrl+z'),
];
}
export function getPlatformRedoBindings(
_platform: string,
): readonly KeyBinding[] {
// Use a stable order for all platforms to minimize churn.
// Ctrl+Shift+Z is the universal primary.
return [
new KeyBinding('ctrl+shift+z'),
new KeyBinding('cmd+shift+z'),
new KeyBinding('alt+shift+z'),
];
}
+26 -5
View File
@@ -149,23 +149,44 @@ describe('keyMatchers', () => {
{
command: Command.UNDO,
positive: [
createKey('z', { shift: false, cmd: true }),
createKey('z', { shift: false, alt: true }),
...(process.platform === 'win32'
? [createKey('z', { shift: false, ctrl: true })]
: process.platform === 'darwin'
? [createKey('z', { shift: false, cmd: true })]
: [
createKey('z', { shift: false, alt: true }),
createKey('z', { shift: false, cmd: true }),
createKey('z', { shift: false, ctrl: true }),
]),
...(process.platform !== 'linux'
? [createKey('z', { shift: false, alt: true })]
: []),
],
negative: [
createKey('z'),
createKey('z', { shift: true, cmd: true }),
createKey('z', { shift: false, ctrl: true }),
...(process.platform === 'darwin'
? [createKey('z', { shift: false, ctrl: true })]
: []),
...(process.platform === 'win32'
? [createKey('z', { shift: false, cmd: true })]
: []),
],
},
{
command: Command.REDO,
positive: [
createKey('z', { shift: true, cmd: true }),
...(process.platform === 'win32'
? []
: [createKey('z', { shift: true, cmd: true })]),
createKey('z', { shift: true, alt: true }),
createKey('z', { shift: true, ctrl: true }),
],
negative: [createKey('z'), createKey('z', { shift: false, cmd: true })],
negative: [
createKey('z'),
createKey('z', { shift: false, cmd: true }),
createKey('y', { shift: false, ctrl: true }),
],
},
// Screen control