Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/components/shared/text-buffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,26 @@ describe('useTextBuffer', () => {
expect(state.viewportVisualLines).toEqual(['l1', 'l2', 'l3']);
expect(state.visualCursor).toEqual([0, 0]);
});

it('moves left across a hard-wrapped single-line boundary', () => {
const { result } = renderHook(() =>
useTextBuffer({
initialText: '1234567890ABCDE',
initialCursorOffset: 10,
viewport: { width: 10, height: 1 },
isValidPath: () => false,
}),
);

expect(getBufferState(result).viewportVisualLines).toEqual(['ABCDE']);

act(() => result.current.move('left'));

const state = getBufferState(result);
expect(state.cursor).toEqual([0, 9]);
expect(state.visualCursor).toEqual([0, 9]);
expect(state.viewportVisualLines).toEqual(['1234567890']);
});
});

describe('Undo/Redo', () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/cli/src/ui/components/shared/text-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,18 @@ function textBufferReducerLogic(
} else if (newVisualRow > 0) {
newVisualRow--;
newVisualCol = cpLen(visualLines[newVisualRow] ?? '');
const previousMapping = visualToLogicalMap[newVisualRow];
if (previousMapping) {
const [previousLogRow, previousLogStartCol] = previousMapping;
const previousCursorCol = previousLogStartCol + newVisualCol;
if (
previousLogRow === cursorRow &&
previousCursorCol === cursorCol &&
newVisualCol > 0
) {
Comment thread
DragonnZhang marked this conversation as resolved.
Resolved
newVisualCol--;
}
}
}
break;
case 'right':
Expand Down
Loading