diff options
| author | Justin Mahood <[email protected]> | 2025-08-05 16:29:37 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-05 23:29:37 +0000 |
| commit | 91035ad7b0a6d976c003f37fef9513da8f3635e9 (patch) | |
| tree | 39234632a5c2fa23e3212cb9e6429cf1474c1922 /packages/cli/src/ui/hooks/vim.test.ts | |
| parent | 12a9bc3ed94fab3071529b5304d46bcc5b4fe756 (diff) | |
Fix(vim): Fix shell mode in Vim mode (#5567)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/hooks/vim.test.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/vim.test.ts | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/packages/cli/src/ui/hooks/vim.test.ts b/packages/cli/src/ui/hooks/vim.test.ts index f939982f..0139119e 100644 --- a/packages/cli/src/ui/hooks/vim.test.ts +++ b/packages/cli/src/ui/hooks/vim.test.ts @@ -1203,7 +1203,9 @@ describe('useVim hook', () => { }); // Press escape to clear pending state - exitInsertMode(result); + act(() => { + result.current.handleInput({ name: 'escape' }); + }); // Now 'w' should just move cursor, not delete act(() => { @@ -1215,6 +1217,69 @@ describe('useVim hook', () => { expect(testBuffer.vimMoveWordForward).toHaveBeenCalledWith(1); }); }); + + describe('NORMAL mode escape behavior', () => { + it('should pass escape through when no pending operator is active', () => { + mockVimContext.vimMode = 'NORMAL'; + const { result } = renderVimHook(); + + const handled = result.current.handleInput({ name: 'escape' }); + + expect(handled).toBe(false); + }); + + it('should handle escape and clear pending operator', () => { + mockVimContext.vimMode = 'NORMAL'; + const { result } = renderVimHook(); + + act(() => { + result.current.handleInput({ sequence: 'd' }); + }); + + let handled: boolean | undefined; + act(() => { + handled = result.current.handleInput({ name: 'escape' }); + }); + + expect(handled).toBe(true); + }); + }); + }); + + describe('Shell command pass-through', () => { + it('should pass through ctrl+r in INSERT mode', () => { + mockVimContext.vimMode = 'INSERT'; + const { result } = renderVimHook(); + + const handled = result.current.handleInput({ name: 'r', ctrl: true }); + + expect(handled).toBe(false); + }); + + it('should pass through ! in INSERT mode when buffer is empty', () => { + mockVimContext.vimMode = 'INSERT'; + const emptyBuffer = createMockBuffer(''); + const { result } = renderVimHook(emptyBuffer); + + const handled = result.current.handleInput({ sequence: '!' }); + + expect(handled).toBe(false); + }); + + it('should handle ! as input in INSERT mode when buffer is not empty', () => { + mockVimContext.vimMode = 'INSERT'; + const nonEmptyBuffer = createMockBuffer('not empty'); + const { result } = renderVimHook(nonEmptyBuffer); + const key = { sequence: '!', name: '!' }; + + act(() => { + result.current.handleInput(key); + }); + + expect(nonEmptyBuffer.handleInput).toHaveBeenCalledWith( + expect.objectContaining(key), + ); + }); }); // Line operations (dd, cc) are tested in text-buffer.test.ts |
