Registry Mirror
Skip to content

Conversation

@benvinegar

@benvinegar benvinegar commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to merged #1143. Paced wheel roundtrips now restore the clicked line, but wheel-up events arriving in one stdin burst can return the viewport without completing the cursor unwind. Reproduced by clicking R2, scrolling down five times with redraws between events, returning with five wheel-up events in one write, and pressing c: the original implementation opened a draft at R4.

  • Retain only the original displaced cursor and restore it directly when visible, including when a larger return skips intermediate viewport-edge stops. Restoration uses constant memory and one remembered-stop bounds lookup per update, rather than scanning a growing history.
  • Replace hard-coded highlight colors with before/after code-cell background comparisons so the PTY assertions do not depend on the user's theme.
  • Add five- and ten-event PTY regressions plus unit coverage for skipped stops and a 4,096-stop journey with bounded remembered-stop lookup work.
  • Add a patch Changeset.

This stays in the existing terminal cursor/viewport planning path; it adds no review semantics, protocol, dependencies, or public API.

Verification

On Linux, after rebasing onto current main:

  • bun run typecheck — passed.
  • bun run test — 4,792 passed, 13 skipped, zero failures across both shards.
  • bun test packages/hunk/src/ui/lib/lineCursors.test.ts test/pty/comment-target.test.ts — 48 passed, including all seven comment-target PTY cases.
  • bun run test:tty-smoke — 10 passed.
  • bun run test:integration — 223 passed, one skipped, six existing pager failures. Reproduced the same six failures with bun test test/pty/pager.test.ts on main at b237c18c (six passed, six failed); the failures concern pager chrome/navigation, not cursor restoration.
  • Targeted oxfmt, oxlint, and git diff --check — passed.

macOS and Windows were not tested locally.

Real-UI demo

Verified in the actual Hunk TUI in a Herdr pane (121 columns × 66 terminal rows, split mode, github-dark-default, visible line numbers, no sidebar). Compared a 160-line TypeScript file pair using the modified source:

bun run packages/hunk/src/main.tsx diff \
  --files /tmp/hunk-wheel-demo-JLWUP4/before.ts /tmp/hunk-wheel-demo-JLWUP4/after.ts \
  --mode split --line-numbers --no-sidebar --no-extensions \
  --theme github-dark-default --wheel-scroll-lines 3

Clicked right-side line 2, sent 25 paced wheel-down events, returned with one 25-event wheel-up burst, and pressed c. The draft remained anchored at R2. Also verified that opening a draft before scrolling targeted R2. The live demo was shown to the user; no screenshot/video attachment was recorded.

This PR description was generated by Pi using GPT-6.1-sol

@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Fixes comment target restoration during rapid scroll events.

The PR appears safe to merge, with a non-blocking concern about scanning growing cursor history during long scroll journeys.

Findings

  1. P2 Long scrolls do more work ▶
Fix with agent prompt
### Issue 1
packages/hunk/src/ui/lib/lineCursors.ts:329-330
`clampLineCursorToViewport` now checks every remembered stop on each viewport move. While scrolling farther down a long diff, those stops stay off-screen and `DiffPane` keeps adding new ones. Across k clamp hops, this does roughly k² bounds checks instead of checking one remembered stop per update. That can make long scroll journeys less responsive.

Avoid walking the entire history on every update, for example by indexing remembered stops by their measured positions.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Restores the oldest visible remembered cursor when a wheel burst skips intermediate stops.

  • Batched wheel returns restore the clicked comment line.

Reviews (1) · Last reviewed commit: "fix(ui): restore comment targets after b..." · Reviewed by Greptile

Comment thread packages/hunk/src/ui/lib/lineCursors.ts Resolved
@benvinegar
benvinegar merged commit 4acc46f into main Oct 12, 2026
13 checks passed
@vercel

vercel Bot commented Oct 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
hunk-web Ignored Ignored Oct 12, 2026 5:51pm UTC

Request Review

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