Fix #167 r2: measure-based gutter rows realign with wrapped lines #203

Closed
fen wants to merge 0 commits from fix-167-r2 into dev
Collaborator

Fixes #167 (QA fail on the #167 follow-up).

Two defects in the previous fix:

  1. renumber() referenced an undefined tops variable in the requestAnimationFrame re-verification pass, so a wrap toggle that reflowed a partially filled last visual row could leave stale, non-idempotent numbering (one extra blank row after OFF-to-ON at some widths).

  2. Row accounting was derived from per-span heights while the code column also renders newline text nodes between .codeline blocks, so the gutter could drift from the code column's real visual rows.

Changes (internal/web/static/paste-lines.js only):

  • renumber() now measures each .codeline's real rendered offsetTop and places every number on the visual row its line starts on (a line wrapping to N rows gets its number on the first of them), padding filler rows in between, so gutter rows always reproduce the code column's actual visual rows.
  • the rAF re-verification pass is fixed and self-corrects placement if reflow moves any line.
  • wrap OFF path unchanged: plain '1\n2\n3\n4' with one number per logical line.

Verified in headless Chromium against a local build (test paste: 4 lines, line 3 a 300-char unbroken token, wrap ON): number-to-first-visual-row alignment exact at 1200px and 640px, wrap OFF untouched, repeated toggle cycles stable, no horizontal scrolling (overflow-wrap anywhere), console free of CSP violations; go build ./... and go test ./... pass.

Fixes #167 (QA fail on the #167 follow-up). Two defects in the previous fix: 1) renumber() referenced an undefined `tops` variable in the requestAnimationFrame re-verification pass, so a wrap toggle that reflowed a partially filled last visual row could leave stale, non-idempotent numbering (one extra blank row after OFF-to-ON at some widths). 2) Row accounting was derived from per-span heights while the code column also renders newline text nodes between .codeline blocks, so the gutter could drift from the code column's real visual rows. Changes (internal/web/static/paste-lines.js only): - renumber() now measures each .codeline's real rendered offsetTop and places every number on the visual row its line starts on (a line wrapping to N rows gets its number on the first of them), padding filler rows in between, so gutter rows always reproduce the code column's actual visual rows. - the rAF re-verification pass is fixed and self-corrects placement if reflow moves any line. - wrap OFF path unchanged: plain '1\n2\n3\n4' with one number per logical line. Verified in headless Chromium against a local build (test paste: 4 lines, line 3 a 300-char unbroken token, wrap ON): number-to-first-visual-row alignment exact at 1200px and 640px, wrap OFF untouched, repeated toggle cycles stable, no horizontal scrolling (overflow-wrap anywhere), console free of CSP violations; go build ./... and go test ./... pass.
fen added 1 commit 2026-09-10 17:20:26 +00:00
Fix #167 r2: measure-based gutter rows + fix undefined tops ref in renumber
CI / docker (pull_request) Skipped
CI / test (pull_request) Successful in 42s
ec791cc2db
QA of the #167 follow-up found two defects:
1) renumber() referenced an undefined 'tops' variable in the rAF
   re-verification pass, so any wrap toggle that reflowed a partially
   filled last visual row left stale (non-idempotent) numbering.
2) rows were derived from per-span heights while the code column also
   renders newline text nodes between .codeline blocks, so the gutter
   could drift from the code column's real visual rows.

renumber() now measures each .codeline's actual offsetTop and places
every number on the visual row its line starts on (a line wrapping to N
rows gets its number on the first of them), pads filler rows in between,
and self-corrects one frame later if reflow moves any line. Wrap-OFF
path stays unchanged ('1
2
3
4'). Verified in headless Chromium:
gutter/code row alignment exact at 1200px and 640px, toggle cycles
stable, no horizontal scroll, no CSP console errors; go build/test pass.
fen closed this pull request 2026-09-10 17:20:54 +00:00
fen deleted branch fix-167-r2 2026-09-10 17:20:54 +00:00

Pull request closed

This pull request cannot be reopened because the branch was deleted.
Sign in to join this conversation.