fix(ui): navigate comments by nearest stream position#5
Merged
Conversation
`}`/`{` from a hunk with no comment of its own snapped to the first or
last comment in the whole review instead of the nearest one, because
`findNextHunkCursor` fell back to `cursors[0]` / `cursors[len-1]` when
the current hunk was absent from the annotated subset.
Add an optional `streamCursors` arg (defaults to `cursors`, a no-op for
existing callers) and a `findNearestCursorIndex` helper that locates the
current hunk in full review-stream order and picks the nearest annotated
cursor in the travel direction, non-cyclic. Thread the full `hunkCursors`
stream into `moveToAnnotatedHunk` — the only runtime call site.
Backports modem-dev/hunk#315, adapted to dunk's precomputed-index
signature and on-disk comments model.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Backport of modem-dev/hunk#315. PR 1 of a series bringing over genuinely-missing upstream fixes (most of hunk's good work is already independently in dunk).
}/{(next/previous comment) from a hunk that has no comment of its own snapped to the first or last comment in the entire review instead of the nearest one in review-stream order. Root cause:findNextHunkCursorfell back tocursors[0]/cursors[len-1]whenever the current hunk was absent from the annotated subset.What was changed
findNextHunkCursorgains an optionalstreamCursorsarg (defaults tocursors, so existing callers are a behavioral no-op) plus afindNearestCursorIndexhelper that locates the current{fileId,hunkIndex}in full review-stream order and picks the nearest annotated cursor in the travel direction. Non-cyclic — clamps to the nearest edge, matching existing hunk navigation.hunkCursorsstream is threaded intomoveToAnnotatedHunk(useReviewController), the only runtime call site.buildReviewStreamderiveshunkCursorsandannotatedHunkCursorsfrom the samevisibleFilesatomically, so the stream and the annotated subset are always consistent.cursorIndexMap) and on-disk comments model — not a copy of upstream.Expert-reviewed (advice incorporated: added the controller-level regression test, the empty-annotated assertion, and the stream-order invariant comment).
Verification
bun run typecheck,bun run lint: clean.hunks.test.ts+useReviewController.test.tsx: 14 pass. New unit cases cover nearest-in-stream selection (both directions), non-cyclic clamp, and empty-annotated →null. New controller-level test exercisesmoveToAnnotatedHunkfrom an unannotated middle hunk and asserts it lands on the nearest annotated hunk (not first/last) — this is the regression at the level the behavior lives.CLAUDE.md.🤖 Generated with Claude Code