Skip to content

Commit 4dbb6d1

Browse files
MukundaKattahotmanxp
authored andcommitted
fix(cli): ignore unmapped vim normal keys (google-gemini#27102)
1 parent 88e5495 commit 4dbb6d1

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

packages/cli/src/ui/hooks/vim-passthrough.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,24 @@ describe('useVim passthrough', () => {
8181

8282
expect(handled).toBe(false);
8383
});
84+
85+
it.each(['H', 'M', 'Q', 'm'])(
86+
'should ignore unmapped printable key %s in NORMAL mode',
87+
async (sequence) => {
88+
mockVimContext.vimMode = 'NORMAL';
89+
const { result } = await renderHook(() =>
90+
useVim(mockBuffer as TextBuffer),
91+
);
92+
93+
let handled = false;
94+
act(() => {
95+
handled = result.current.handleInput(
96+
createKey({ name: sequence, sequence, insertable: true }),
97+
);
98+
});
99+
100+
expect(handled).toBe(true);
101+
expect(mockBuffer.handleInput).not.toHaveBeenCalled();
102+
},
103+
);
84104
});

packages/cli/src/ui/hooks/vim.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,8 +1486,14 @@ export function useVim(buffer: TextBuffer, onSubmit?: (value: string) => void) {
14861486
// Unknown command, clear count and pending states
14871487
dispatch({ type: 'CLEAR_PENDING_STATES' });
14881488

1489-
// Ignore any Insertable key in Normal Mode
1490-
if (normalizedKey.insertable) {
1489+
// Ignore unmapped Insertable keys in Normal Mode, but let
1490+
// modifier-key chords (ctrl/alt/cmd) fall through to other handlers.
1491+
if (
1492+
normalizedKey.insertable &&
1493+
!normalizedKey.ctrl &&
1494+
!normalizedKey.alt &&
1495+
!normalizedKey.cmd
1496+
) {
14911497
return true;
14921498
}
14931499

0 commit comments

Comments
 (0)