Skip to content

feat(gitview): scroll the diff pane sideways to reach long lines - #35

Merged
ChmaraX merged 4 commits into
mainfrom
fix/26-diff-horizontal-scroll
Nov 14, 2026
Merged

ChmaraX merged 4 commits into
mainfrom
fix/26-diff-horizontal-scroll

Conversation

@ChmaraX

@ChmaraX ChmaraX commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Fixes #26

Replaces #30, which closed when its base branch (#29's) was deleted on merge.

Problem

In the diff pane, a line wider than the pane was cut off at the right edge, and nothing brought the rest into view: no key, sideways swipe or shift+scroll. For minified JSON, lockfiles or long strings, the changed part of the line was often simply invisible.

Fix

The diff pane now scrolls sideways:

  • h / l (and ← / →) move 4 columns; they're listed in the keys card.
  • A sideways trackpad swipe or shift+wheel works; each swipe locks to its main direction, so reading down doesn't drift sideways.
  • A thin bar at the bottom shows the position and can be dragged.
  • The range comes from the file's widest line (wide characters count as two columns), and each file starts at the left edge.

Only the text moves: row colors, the selection, the cursor bar, note cards and the commit box stay put. The file list is unchanged. I chose sideways scrolling over soft wrap so every row keeps one height, which the cursor, selection and notes rely on. Line numbers still scroll with the text; pinning them is a possible follow-up.

Proof

Before: the long line is cut at the pane edge
After pressing l: the end of the line is in view

A new step in herdr-app/e2e/run.sh traces the pane's sideways offset and asserts: l raises it, enough l stops with the line's end at the right edge (offset 1112 = range 1416 − width 304), h returns to 0, another file starts at 0. node --test herdr-app/test passes (46/46).

Add the Scroller's sideways range/clamp unit tests and a private-app E2E
step that opens a file with a line far wider than the pane and asserts
that pressing l/h moves the diff pane (the tail of a clipped line becomes
reachable). Both fail on the current code: the Scroller has no sideways
API and the diff pane binds no l/h, so the shots stay byte-identical.
…nes (#26)

A line wider than the diff pane was cut at the right edge with no way to
see the rest. Add opt-in horizontal scrolling to the shared Scroller (the
file list leaves it off and is unchanged):

- h/l and left/right scroll 4 columns a press; a trackpad's sideways
  swipe and shift+wheel scroll too; a draggable bottom thumb shows the
  position. The keys card lists them; in Preview they say "works in Diff".
- The sideways range is measured, not estimated: each row reports its
  natural width, the range is the widest row seen plus two columns of
  room, it only grows (so it can't oscillate), and it resets on another
  file. One column's width comes from an invisible probe in the diff font.
- Row tints and the selection paint across the full content width, while
  the cursor bar, note cards and the composer stay in the visible width.
- All widths go through #25's unzoom() so they are right at any zoom.
Round 2 of the review's fix list, written failing first:
- diffview.test.mjs pins displayColumns/widestColumns (wide glyphs count as
  two columns), the pure logic the data-driven range leans on.
- drop scroller.test.mjs, whose tests poked the Scroller's internal fields.
- run.sh's long-line step traces the diff pane's offsetX / rangeX / viewW and
  asserts behaviour (l raises the offset, enough l stops at range - width, h
  returns to 0, another file resets to 0); it SKIPs when no frames draw.
…wheel (#26)

Reworks round 1 per the code review's fix list:
- renderRow keeps the row tint, selection, cursor wash and bar on the outer
  row (bar at the left edge, no compensation); only the text moves, in one
  absolute layer at left(-offset). Drops ctx.contentW and the left(sx) trick.
- the sideways range comes from the data, not from measuring drawn rows: the
  widest row's display columns (wide glyphs count as two) x the probed column
  width + 2 columns, recomputed when the diff loads and when the column width
  changes. So it shrinks after a reload or a smaller font. Drops measureWidth,
  ctx.onWidth, the per-row on_size_change and the only-grows rule.
- wheel: always apply delta.x; delta.y sideways only on shift with delta.x 0;
  the horizontal scroller locks each event to its dominant axis, so a vertical
  swipe no longer drifts sideways.
- reset the sideways offset whenever the shown file changes, including the
  error path of loadDiff (one resetScroll helper for both).
- the probe reports one column's width (the /10 and unzoom live in diffview),
  passes cx and redraws on a change. Scroller mutators return 'changed'; the
  caller notifies. A thumb helper serves both axes.
- names: ctx.offsetX (offset) vs GitDiff.sideways(dir) (action); the Scroller's
  width field is 'content', no more contentW/scrollX collisions.
- traceFields carries offsetX/rangeX/viewW so the e2e can watch the scroll.
@ChmaraX
ChmaraX merged commit 35ad2b9 into main Nov 14, 2026
3 of 4 checks passed
@ChmaraX
ChmaraX deleted the fix/26-diff-horizontal-scroll branch November 14, 2026 16:47
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.

The app's diff pane clips lines wider than the pane, with no way to scroll sideways

1 participant