Skip to content

fix(selection): correct absoluteRow mapping in select() and selectAll() - #234

Open
jedafe wants to merge 1 commit into
coder:mainfrom
jedafe:fix/select-absoluterow
Open

jedafe wants to merge 1 commit into
coder:mainfrom
jedafe:fix/select-absoluterow

Conversation

@jedafe

@jedafe jedafe commented Dec 1, 2026

Copy link
Copy Markdown

Summary

select() and selectAll() treated getViewportY() — the distance scrolled back from the live bottom — as an absolute row index. Whenever scrollback existed, both anchored selections on scrollback-head rows instead of the visible viewport:

  • select(row, col, len): absoluteRow = viewportY + row landed viewportY rows too deep in scrollback, silently selecting the wrong line.
  • selectAll(): produced [viewportY, viewportY + rows) — the wrong band of scrollback, disjoint from what the user sees.

Fix

  • select() now maps viewport rows through viewportRowToAbsolute() — the same mapping selectLines() already uses.
  • selectAll() now spans the whole buffer: [0, getScrollbackLength() + rows - 1].

Tests

Two regression tests, run against real WASM scrollback (50 lines written into a 24-row terminal):

  • selectAll selects scrollback plus screen, not scrollback-head rows — selection text contains scrollback (SB000–SB026) and screen rows.
  • select() anchors on the viewport, not scrollback-head rows — select(0, 0, 5) returns the top visible line (SB027), previously SB000.

Both fail on main, pass with the fix. prettier, biome, tsc --noEmit, and bun test (361 tests) are clean.

Refs #233 — the selection half of that issue (the outside-click clearSelection() on document clicks is a separate design question, not addressed here).

Discovery

Found via terminu's ctx-menu "select all" → copy producing scrollback-head text instead of the screen; verified against selection-manager.ts in lib/.

Both methods treated getViewportY() — the distance scrolled back from
the live bottom — as an absolute row index. Whenever scrollback existed
they anchored selections on scrollback-head rows instead of the visible
viewport, so select() silently selected the wrong line and selectAll()
produced text disjoint from what the user saw.

select() now maps viewport rows through viewportRowToAbsolute(), the
same mapping selectLines() uses. selectAll() now spans the whole
buffer: [0, scrollbackLength + rows - 1], matching what getSelection()
can extract and what "select all" means.

Regression tests cover both: selectAll() over scrollback+screen, and
select() on viewport row 0 with scrollback present.

Fixes coder#233 (selection part)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant