Skip to content

Add hover previews for node references (#34) - #2024

Merged
mstomar125 merged 3 commits into
mainfrom
issue-34-hover-previews
Aug 11, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-34-hover-previews

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

Adds hover/focus preview cards for node references — the last remaining gap on #34 (everything else in the original spec was already built; see the re-scope comment on the issue).

Both reference render paths converge on the same <a class="ns-noderef" href="nodespace://…"> anchor:

  • the markdown-link form emitted by view-mode-renderer.svelte, and
  • the bare [[id]] wikilink form (NodeRefInline).

So a single document-level trigger in app-shell drives previews for all of them, mirroring the existing delegated handleLinkClick handler.

Behavior

  • Hovering or keyboard-focusing a reference shows a card after a short delay (450 ms) with the target node's title and a content snippet.
  • The card is dismissed on mouse-out, blur, Escape, or scroll.
  • Cache-first resolution through SharedNodeStore (getNode → ensureNode); a card shows a loading then not-found state if the node can't be resolved.
  • Deleted/broken references are skipped (they're inert anyway).
  • The card is pointer-events: none, so it never traps the cursor — the reference beneath it owns show/hide entirely.
  • Viewport-aware positioning: prefers below the anchor, flips above when it would overflow, clamps horizontally.

Design notes

  • New shared controller node-ref-preview.svelte.ts owns timing + resolved content; the card component (references/node-ref-preview.svelte) owns only presentation/positioning. One shared instance is rendered near the root of app-shell.
  • The node-id parsing previously inlined in handleLinkClick is extracted to extractNodeIdFromHref in external-links.ts and reused by both the click and preview paths.
  • The elaborate decoration-overlay / mock-element / #task machinery from the original 2025 spec was intentionally dropped — the real reference model is rendered markdown links, and the data layer already exists (per the issue's re-scope).

Tests

  • node-ref-preview.test.ts — title/snippet builders + the show/hide state machine (delay, cache-first vs fetch, not-found, async-race guard, and the no-reset-on-repeat-hover guard). Uses vi.spyOn on the real sharedNodeStore singleton (no vi.mock, so nothing leaks under the forks pool).
  • external-links.test.ts — extended with extractNodeIdFromHref cases (standard/node//query-param/empty/non-nodespace).
  • Full suite green: 195 files / 4497 tests; lint + svelte-check clean.

Closes #34.

🤖 Generated with Claude Code

mstomar125 and others added 3 commits August 11, 2026 08:02
Node references — both the markdown-link form rendered by view-mode-renderer
and the bare `[[id]]` wikilink form (NodeRefInline) — now show a preview card
on hover or keyboard focus with the target node's title and a content snippet.

Both render paths resolve to the same `a.ns-noderef` anchor, so a single
document-level trigger in app-shell drives them all, mirroring the existing
delegated click handler. A shared controller owns the reveal delay and
cache-first resolution (SharedNodeStore); the card renders itself with
viewport-aware positioning and is pointer-events:none so it never traps the
cursor. Dismissed on mouse-out, blur, Escape, or scroll. Deleted (broken)
references are skipped.

The node-id parsing previously inlined in app-shell's click handler is
extracted to `extractNodeIdFromHref` and reused by both the click and preview
paths.

Co-Authored-By: Claude <[email protected]>
Crossing nested spans inside a reference re-fires requestPreview; guard on the
pending id alone so the delay keeps counting from the first hover instead of
restarting each time (which could keep the card from ever appearing).

Co-Authored-By: Claude <[email protected]>
- Re-measure the card position after content resolves (loading → title+snippet).
  The positioning effect now depends on the resolved-content fields, so the
  flip-above/clamp decision uses the final card height instead of the shorter
  loading card — a tall card near the viewport bottom no longer overflows.
- Link the active reference anchor to the card via aria-describedby while shown,
  so keyboard/screen-reader users get the same title+snippet on focus.
- Scope focusout dismissal to reference anchors, so a hover-shown card isn't torn
  down by an unrelated element losing focus.
- Track the pending anchor alongside the pending id, so the same node referenced
  by two anchors re-anchors instead of keeping the stale one.

Co-Authored-By: Claude <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE (self-review, mstomar125)

Two-pass adversarial review. First pass flagged a real MAJOR positioning bug — the card measured its loading size and never re-measured after content resolved, so a reference near the viewport bottom got a clipped card — plus three minors (a11y association, unscoped focusout, stale anchor for a repeated node id). All four addressed in fd148d53:

  • Positioning effect now depends on the resolved-content fields → re-measures at the final title+snippet height before the flip/clamp decision.
  • aria-describedby links the active reference to the card while shown (keyboard/SR parity with hover); cleared on hide/re-anchor/unmount.
  • focusout scoped to reference anchors so a hover-shown card isn't dismissed by unrelated blur.
  • Pending anchor tracked alongside pending id → a node referenced by two anchors re-anchors correctly, without reintroducing the nested-span timer-reset.

Second pass verified all four fixes correct with no new defects. Gate green on each push; full suite 195 files / 4500 tests, lint + svelte-check clean.

@mstomar125
mstomar125 merged commit 430a27c into main Aug 11, 2026
@mstomar125
mstomar125 deleted the issue-34-hover-previews branch August 11, 2026 06:23
@mstomar125 mstomar125 mentioned this pull request Aug 11, 2026
21 tasks
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.

Hover previews for node references

1 participant