Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 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,9 +1397,29 @@ 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.
newVisualCol--;
}
}
}
break;
case 'right':
// No stall-fix needed here (unlike 'left' above): the cursor
// resolver (calculateVisualCursorFromLayout) selects segments with
// a strict `logicalCol < nextStartColInLogical`, so a cursor at a
// hard-wrap boundary always lands at the START of the next visual
// row, not the end of the current one — wrapping right never maps
// back to the same logical position. If that segment selection ever
// changes (e.g. `<` → `<=`), a symmetric decrement would be needed
// here to avoid a mirror-image right-movement stall.
newPreferredCol = null;
if (newVisualCol < currentVisLineLen) {
newVisualCol++;
Expand Down
Loading