From 51f642f0a9fac68b9ab07d4f5cdbef3320fe9ed5 Mon Sep 17 00:00:00 2001 From: mkusaka Date: Fri, 22 Aug 2025 13:39:58 +0900 Subject: [PATCH] fix: Ctrl+E should move to current line end, not buffer end (#6729) Co-authored-by: Jacob Richman Co-authored-by: Arya Gummadi --- .../src/ui/components/InputPrompt.test.tsx | 42 ++++++++++++++++++- .../cli/src/ui/components/InputPrompt.tsx | 1 - 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/ui/components/InputPrompt.test.tsx b/packages/cli/src/ui/components/InputPrompt.test.tsx index a3346490..c6fba806 100644 --- a/packages/cli/src/ui/components/InputPrompt.test.tsx +++ b/packages/cli/src/ui/components/InputPrompt.test.tsx @@ -119,9 +119,9 @@ describe('InputPrompt', () => { visualScrollRow: 0, handleInput: vi.fn(), move: vi.fn(), - moveToOffset: (offset: number) => { + moveToOffset: vi.fn((offset: number) => { mockBuffer.cursor = [0, offset]; - }, + }), killLineRight: vi.fn(), killLineLeft: vi.fn(), openInExternalEditor: vi.fn(), @@ -1469,4 +1469,42 @@ describe('InputPrompt', () => { unmount(); }); }); + + describe('Ctrl+E keyboard shortcut', () => { + it('should move cursor to end of current line in multiline input', async () => { + props.buffer.text = 'line 1\nline 2\nline 3'; + props.buffer.cursor = [1, 2]; + props.buffer.lines = ['line 1', 'line 2', 'line 3']; + + const { stdin, unmount } = renderWithProviders( + , + ); + await wait(); + + stdin.write('\x05'); // Ctrl+E + await wait(); + + expect(props.buffer.move).toHaveBeenCalledWith('end'); + expect(props.buffer.moveToOffset).not.toHaveBeenCalled(); + unmount(); + }); + + it('should move cursor to end of current line for single line input', async () => { + props.buffer.text = 'single line text'; + props.buffer.cursor = [0, 5]; + props.buffer.lines = ['single line text']; + + const { stdin, unmount } = renderWithProviders( + , + ); + await wait(); + + stdin.write('\x05'); // Ctrl+E + await wait(); + + expect(props.buffer.move).toHaveBeenCalledWith('end'); + expect(props.buffer.moveToOffset).not.toHaveBeenCalled(); + unmount(); + }); + }); }); diff --git a/packages/cli/src/ui/components/InputPrompt.tsx b/packages/cli/src/ui/components/InputPrompt.tsx index 215962ce..1547e2c8 100644 --- a/packages/cli/src/ui/components/InputPrompt.tsx +++ b/packages/cli/src/ui/components/InputPrompt.tsx @@ -482,7 +482,6 @@ export const InputPrompt: React.FC = ({ } if (keyMatchers[Command.END](key)) { buffer.move('end'); - buffer.moveToOffset(cpLen(buffer.text)); return; } // Ctrl+C (Clear input)