Skip to content

apps/mac: verify and harden click-to-jump from PDF preview to source - #1100

Merged
d-q222 merged 7 commits into
mainfrom
agent/daniel-muse-lead/source-pdf-click-to-jump
Sep 27, 2026
Merged

d-q222 merged 7 commits into
mainfrom
agent/daniel-muse-lead/source-pdf-click-to-jump

Conversation

@d-q222

@d-q222 d-q222 commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Overleaf-gap as filed: no SyncTeX-equivalent click-to-jump. Investigation found this was already partially wired: `PageV2View`'s tap handler already called `onSelect(hit)` on a successful `V2Geometry.hit`, and `onSelect` was already connected to `navigateV2 → Navigation.navigateExactly`, which already moves the caret to the hit's source span. There was no test exercising the actual click-coordinate flow end-to-end, so the gap was real from a verification standpoint even though the underlying wiring existed.

Changes:

  • Added `V2Geometry.hit(page:viewPoint:scale:)`, a coordinate-precision-preserving overload used by both the hover and tap handlers, replacing manual pre-division of the point into page-local coordinates.
  • New regression test computing a real scaled view-space click point for a known glyph run and asserting the click lands the caret at the exact expected source byte and substring.

`xcodebuild test -scheme FlashTeXMac -only-testing:FlashTeXMacTests/PreviewV2ShellTests`: 10 passed, 0 failed (re-verified after rebase), including the pre-existing 9 tests with no regressions.

🤖 Generated with Claude Code

d-q222 added a commit that referenced this pull request Sep 25, 2026
Round 2 independent review confirmed the resolveTap extraction is sound
(no duplicated hit-testing, coordinate math consistent, V2Geometry.hit
wrapper forwards correctly) but found the test only ever passed
navigation: nil, so .link was unreachable and untested. Added a sibling
test at the same tap location with a matching Navigation.Link, asserting
resolveTap returns .link before falling through to span selection.

Implementation-Agent: daniel-muse-lead (Claude Sonnet)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: d-q222 <[email protected]>
Investigated the reported gap ("no SyncTeX-equivalent click-to-jump"): the
click handler in PageV2View's onTapGesture already called onSelect(hit) on
a successful V2Geometry.hit, and onSelect was already wired through to
navigateV2 -> Navigation.navigateExactly, which already moves the editor
caret to the hit's source span. That existing path had no test exercising
the actual click coordinate flow end-to-end, so the "gap" was real from a
verification standpoint even though the wiring existed.

Adds a coordinate-precision-preserving V2Geometry.hit(page:viewPoint:scale:)
overload (used by both the hover and tap handlers) instead of pre-dividing
the point into page-local coordinates inline, and a regression test
(testScaledPreviewClickNavigatesToTheClickedSourceSpan) that computes a real
scaled view-space click point for a known glyph run and asserts the click
lands the caret at the exact expected source byte and substring.

xcodebuild test -scheme FlashTeXMac -only-testing:FlashTeXMacTests/PreviewV2ShellTests:
10 passed, 0 failed (new test included, no regressions).

Implementation-Agent: gpt-5.6-luna (Codex, apps/mac:source-pdf-sync)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: d-q222 <[email protected]>
Review found the click-to-jump test called V2Geometry.hit + model.navigateV2
directly, bypassing .onTapGesture's closure and the onSelect wiring, so it
couldn't catch a regression in the actual production tap-handling code.

Extracts the closure's logic (link check, then text-hit fallback) into
resolveTap(location:scale:page:navigation:) -> TapResolution, an Equatable
enum (.link/.select/.none). The closure is now a thin dispatcher over this
function's result. The test now calls resolveTap directly and asserts the
exact .select(hit) value, genuinely exercising the same code the real tap
gesture runs, then still calls navigateV2 on the result to verify the caret
move.

xcodebuild test -scheme FlashTeXMac -only-testing:FlashTeXMacTests/PreviewV2ShellTests:
10 passed, 0 failed.

Implementation-Agent: gpt-5.6-luna (Codex, apps/mac:source-pdf-sync)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: d-q222 <[email protected]>
Round 2 independent review confirmed the resolveTap extraction is sound
(no duplicated hit-testing, coordinate math consistent, V2Geometry.hit
wrapper forwards correctly) but found the test only ever passed
navigation: nil, so .link was unreachable and untested. Added a sibling
test at the same tap location with a matching Navigation.Link, asserting
resolveTap returns .link before falling through to span selection.

Implementation-Agent: daniel-muse-lead (Claude Sonnet)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: d-q222 <[email protected]>
Round 3 review: resolveTap divided location by scale before any validation.
With navigation present and scale <= 0, that produces NaN/infinity, which
DisplayListLinks.ticks then traps converting to Int64. Guard scale > 0 at
the top and return .none. Also rebased onto current main — the previous
diff appeared to delete unrelated operator-limits/hhline code, which was
a stale-branch artifact (both landed on main after this branch was cut),
not an actual regression in this PR.

Implementation-Agent: daniel-muse-lead (Claude Sonnet)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: d-q222 <[email protected]>
@d-q222
d-q222 force-pushed the agent/daniel-muse-lead/source-pdf-click-to-jump branch from a7124f1 to 8d88c1a Compare September 25, 2026 21:14
…olveTap test

Round 4 review: the invalid-scale test only passed navigation: nil, so both
assertions would have passed via V2Geometry.hit alone even without the new
guard -- it never exercised the DisplayListLinks.hit path the guard exists
to protect. Added navigation-present cases with a real link at the tap
point.

Also found the same unguarded scale division in onContinuousHover's
.active case, a sibling of resolveTap that independently calls
DisplayListLinks.hit before validating scale. Same guard, same fallback
(clear hover state) as the .ended case already does.

Verified: xcodebuild test -only-testing:FlashTeXMacTests/PreviewV2ShellTests
-> 12 passed, 0 failed.

Implementation-Agent: daniel-muse-lead (Claude Sonnet)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: d-q222 <[email protected]>
Round 5 review: the scale: -1 case used location (10, 10), which misses
the ffi link rect regardless of the guard -- V2Geometry.hit independently
returns nil there too, so the assertion passed for the wrong reason and
never proved the guard rejects negative scale. Fixed by negating the
link's own page-point midpoint as the location, so location/scale lands
exactly on the link if the guard is removed.

Fail-before demonstrated honestly: weakened the guard to `scale != 0`
(dropping the sign check) and confirmed this exact test then fails;
reverted before commit (touch confirms no stale build reused).

Verified: xcodebuild test -only-testing:FlashTeXMacTests/PreviewV2ShellTests
-> 12 passed, 0 failed.

Implementation-Agent: daniel-muse-lead (Claude Sonnet)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: d-q222 <[email protected]>
@d-q222

d-q222 commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

flashtex-2a/opus-9 review @745646a8d: MERGE-READY

  • Behaviour is preserved: the tap path still hit-tests links first, then source spans via onSelect, now through a testable resolveTap. Hover uses the same order.
  • The scale > 0 guards are sound. Without them a zero scale would give an infinite point, which traps converting to Int64 ticks in DisplayListLinks.ticks. The hover branch also pops the pushed cursor correctly in that case.
  • The new tests exercise the real chain from a scaled click point to resolveTap to navigateV2, and pin caret byte 75 and the "ffi" substring. The test that a link beats a span uses the identical rect, so it proves precedence rather than mere reachability.
  • Body nit: V2Geometry.hit(page:viewPoint:scale:) is not "precision-preserving". It does the same x / scale division as before, so it is a refactor with no numeric change. Also, the pageFrame add/subtract in the tests cancels out, so no layout offset is really tested.
  • Nit: resolveTap/TapResolution sit at module scope. Consider nesting them under V2Geometry to keep the global namespace small.
  • CI green (10/10).

(flashtex-2a/opus-9, mac-m5pro-dq222, independent review for d-q222)

@d-q222
d-q222 merged commit 03e9048 into main Sep 27, 2026
10 checks passed
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