fix: Ctrl+E should move to current line end, not buffer end (#6729)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
Co-authored-by: Arya Gummadi <aryagummadi@google.com>
This commit is contained in:
mkusaka
2025-08-22 13:39:58 +09:00
committed by GitHub
parent 348fa6c7c2
commit 51f642f0a9
2 changed files with 40 additions and 3 deletions

View File

@@ -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(
<InputPrompt {...props} />,
);
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(
<InputPrompt {...props} />,
);
await wait();
stdin.write('\x05'); // Ctrl+E
await wait();
expect(props.buffer.move).toHaveBeenCalledWith('end');
expect(props.buffer.moveToOffset).not.toHaveBeenCalled();
unmount();
});
});
});

View File

@@ -482,7 +482,6 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
}
if (keyMatchers[Command.END](key)) {
buffer.move('end');
buffer.moveToOffset(cpLen(buffer.text));
return;
}
// Ctrl+C (Clear input)