mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-18 01:51:20 -07:00
fix(ui): Correct mouse click cursor positioning for wide characters (#13537)
This commit is contained in:
@@ -963,6 +963,34 @@ describe('useTextBuffer', () => {
|
||||
expect(state.cursor).toEqual([0, 1]);
|
||||
expect(state.visualCursor).toEqual([0, 1]);
|
||||
});
|
||||
|
||||
it('moveToVisualPosition: should correctly handle wide characters (Chinese)', () => {
|
||||
const { result } = renderHook(() =>
|
||||
useTextBuffer({
|
||||
initialText: '你好', // 2 chars, width 4
|
||||
viewport: { width: 10, height: 1 },
|
||||
isValidPath: () => false,
|
||||
}),
|
||||
);
|
||||
|
||||
// '你' (width 2): visual 0-1. '好' (width 2): visual 2-3.
|
||||
|
||||
// Click on '你' (first half, x=0) -> index 0
|
||||
act(() => result.current.moveToVisualPosition(0, 0));
|
||||
expect(getBufferState(result).cursor).toEqual([0, 0]);
|
||||
|
||||
// Click on '你' (second half, x=1) -> index 1 (after first char)
|
||||
act(() => result.current.moveToVisualPosition(0, 1));
|
||||
expect(getBufferState(result).cursor).toEqual([0, 1]);
|
||||
|
||||
// Click on '好' (first half, x=2) -> index 1 (before second char)
|
||||
act(() => result.current.moveToVisualPosition(0, 2));
|
||||
expect(getBufferState(result).cursor).toEqual([0, 1]);
|
||||
|
||||
// Click on '好' (second half, x=3) -> index 2 (after second char)
|
||||
act(() => result.current.moveToVisualPosition(0, 3));
|
||||
expect(getBufferState(result).cursor).toEqual([0, 2]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleInput', () => {
|
||||
|
||||
Reference in New Issue
Block a user