Skip to content

Editor cursor mispositioned when long wrapped lines are present #135

@bananabot9000

Description

@bananabot9000

Symptoms

When a long line wraps across multiple terminal rows in the editor, the cursor gets stuck and arrow keys don't work correctly. The cursor is pinned to the bottom-right of the wrapped line and cannot be moved within the wrapped portions. Pressing down arrow jumps multiple terminal rows instead of moving one row down.

Reproduction:

  1. Paste a long line into the editor (e.g. 200+ characters that wraps across 3+ terminal rows)
  2. Cursor appears stuck at the end of the wrapped content
  3. Down arrow jumps past all wrapped rows to the next editor line instead of moving one terminal row down within the wrap
  4. Cannot position the cursor in the middle of a wrapped line

Still present after #136 (ANSI width fix) and #139 (string-width adoption).

Expected Behaviour

Arrow keys should navigate by terminal coordinates, not editor lines. For a 200-char line wrapped across 3 rows at 80 columns:

> aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|  <- terminal row 1
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|  <- terminal row 2 (wrapped)
aaaaaaaaaaaaaaaa                  <- terminal row 3 (rest)
short second line                 <- next editor line
  • Down from row 1 moves to the same column on row 2 (within the same editor line), not to short second line
  • Up from row 2 moves back to row 1 at the same column
  • Down from row 3 moves to short second line (next editor line starts here)
  • Left/Right at a wrap boundary moves to the end/start of the adjacent terminal row
  • The cursor should always move exactly 1 position in screen terms

This is how VS Code, nano, and other editors handle wrapped lines -- the cursor navigates the screen, not the data.

Verification

Manual:

  1. Run the CLI in a terminal with known width (e.g. 80 columns)
  2. Paste a line longer than the terminal width (e.g. 200 characters)
  3. Press Up/Down arrows -- cursor should move one terminal row at a time within the wrapped line
  4. Cursor should never get stuck, jump multiple rows, or land in the wrong position
  5. Repeat at different terminal widths / zoom levels

Automated:
Unit tests for prepareEditor():

  • 200-char line at 80 cols: cursor on editor line 1 col 0 should have cursorRow = 3 (line 0 wraps across 3 terminal rows)
  • Cursor at col 100 on a wrapped line: cursorRow should reflect being on the second terminal row of the wrap

Related

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions