Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/cli/src/ui/hooks/vim-passthrough.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,24 @@ describe('useVim passthrough', () => {

expect(handled).toBe(false);
});

it.each(['H', 'M', 'Q', 'm'])(
'should ignore unmapped printable key %s in NORMAL mode',
async (sequence) => {
mockVimContext.vimMode = 'NORMAL';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Mutating the shared mockVimContext global object directly inside the test can lead to test pollution and flakiness if other tests are added in the future that assume the default 'INSERT' mode. To ensure test isolation, consider resetting mockVimContext.vimMode to 'INSERT' in the beforeEach block or adding an afterEach block to clean up the shared state.

const { result } = await renderHook(() =>
useVim(mockBuffer as TextBuffer),
);

let handled = false;
act(() => {
handled = result.current.handleInput(
createKey({ name: sequence, sequence, insertable: true }),
);
});

expect(handled).toBe(true);
expect(mockBuffer.handleInput).not.toHaveBeenCalled();
},
);
});
10 changes: 8 additions & 2 deletions packages/cli/src/ui/hooks/vim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1486,8 +1486,14 @@ export function useVim(buffer: TextBuffer, onSubmit?: (value: string) => void) {
// Unknown command, clear count and pending states
dispatch({ type: 'CLEAR_PENDING_STATES' });

// Ignore any Insertable key in Normal Mode
if (normalizedKey.insertable) {
// Ignore unmapped Insertable keys in Normal Mode, but let
// modifier-key chords (ctrl/alt/cmd) fall through to other handlers.
if (
normalizedKey.insertable &&
!normalizedKey.ctrl &&
!normalizedKey.alt &&
!normalizedKey.cmd
) {
return true;
}

Expand Down
Loading