Skip to content

feat(quiz): render anchored code inline (clipped to the anchored lines) - #29

Merged
jonasbrami merged 1 commit into
mainfrom
feat/inline-anchors
May 29, 2026
Merged

feat(quiz): render anchored code inline (clipped to the anchored lines)#29
jonasbrami merged 1 commit into
mainfrom
feat/inline-anchors

Conversation

@jonasbrami

Copy link
Copy Markdown
Owner

What

Makes the per-question code context inline with the question instead of behind a click-to-expand disclosure: the anchored hunk now renders directly under the prompt (fetched on render, always visible).

To keep that readable when a question anchors into a large diff hunk, the inline view is clipped to a tight window around the anchored lines (± 3 context lines), with the anchored lines highlighted and trimmed regions marked by an ellipsis (). Falls back to the full hunk when there's no anchor window to clip to.

Why

The collapsible panel hid the code behind a click; "inline together with the question" is what makes the context actually useful while answering. But always-showing a full 40+ line hunk under every question (and repeated across questions that anchor the same hunk) is overwhelming — hence the clip.

Changes

  • renderAnchor → an always-visible inline panel (file:line header + hunk), fetched on render; cached per path so re-renders don't re-fetch or flash.
  • renderDiff → after scoping to the overlapping hunk(s), clips to [start-3, end+3] on the new side, emits for trimmed head/tail, keeps the @@ header, and highlights anchored lines.
  • CSS: drop the disclosure/summary affordances; add the ellipsis row style.

Frontend only — no backend/schema change.

Testing

  • node --check; full mcp/engine suite green; ruff + ruff format --check clean.
  • Real end-to-end (this is the "run take" check): generated a real quiz with cognit against PR feat(quiz): diff coverage map in the sidebar #27 (5 questions — 4 anchored + mermaid + open) and served it through the real web app + _DiffProvider. Confirmed via DOM that each inline hunk clipped to 12–20 lines (from 46), each with 2 ellipsis markers and the anchored lines highlighted; mermaid diagrams and the diff coverage map ("1 of 5 files probed") all render. Screenshots shared.

🤖 Generated with Claude Code

The anchored hunk now renders inline with the question (always visible, fetched on
render) instead of behind a click-to-expand panel — the code context is right there
next to the prompt. To keep that readable when a question anchors into a large diff
hunk, the inline view is clipped to a tight window around the anchored lines
(± a few context lines), with the anchored lines highlighted and trimmed regions
marked by an ellipsis. Falls back to the full hunk when there's no window to clip to.

Verified end-to-end by generating a real quiz with `cognit` against PR #27 and
serving it through the real web app: 5 questions (4 anchored + mermaid + open), each
inline hunk clipped to 12–20 lines (from 46) with ellipsis + highlighting, plus the
diff coverage map. Frontend only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jonasbrami
jonasbrami merged commit 7ab6b9f into main May 29, 2026
2 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