Background
Split out from the descoped #115 Phase D. Phase A + B.1 of the diff viewer have shipped; this is the remaining "polish" item that's still relevant.
Problem
When a Watcher user wants to share a specific change with someone (a colleague, a stakeholder, a comment in another tool), they currently have to send the whole /changes/{id} URL — there's no way to point at a specific line within the diff. For long diffs that means the recipient has to scroll-hunt for what's being referenced.
Goal
Each line in the diff (and ranges) gets a stable, copyable URL fragment, e.g.:
https://watcher.exe.xyz/changes/{id}#L42 — single line
https://watcher.exe.xyz/changes/{id}#L42-L57 — range
When the URL with a fragment is loaded, the page should:
- Auto-scroll to the referenced line(s)
- Visually highlight the referenced span (subtle background tint)
Approach sketch
diff2html-ui renders each line as .d2h-code-line / .d2h-code-side-line with an associated line number cell. Two pieces:
- Anchor IDs at render time (
src/dashboard/static/js/diff-viewer.js): after Diff2HtmlUI.draw(), walk the rendered DOM and add id="L{n}" to each line number cell. Add a small "copy link" affordance on hover (chip near the line number that copies ${location.pathname}${location.search}#L{n} to clipboard).
- Range selection — shift-click a second line number to extend a selection;
#L{a}-L{b} form. Standard pattern from GitHub.
- Fragment handling on load — read
location.hash, scroll the line into view, apply a .d2h-line-anchor-target class for highlight.
Acceptance
Out of scope
- Cross-mode anchor preservation (line 42 in Extracted ≠ line 42 in Raw — that's a different feature)
- Persisting selections in
localStorage
Dependencies
None — purely client-side enhancement on top of existing diff2html-ui mount.
Related
Background
Split out from the descoped #115 Phase D. Phase A + B.1 of the diff viewer have shipped; this is the remaining "polish" item that's still relevant.
Problem
When a Watcher user wants to share a specific change with someone (a colleague, a stakeholder, a comment in another tool), they currently have to send the whole
/changes/{id}URL — there's no way to point at a specific line within the diff. For long diffs that means the recipient has to scroll-hunt for what's being referenced.Goal
Each line in the diff (and ranges) gets a stable, copyable URL fragment, e.g.:
https://watcher.exe.xyz/changes/{id}#L42— single linehttps://watcher.exe.xyz/changes/{id}#L42-L57— rangeWhen the URL with a fragment is loaded, the page should:
Approach sketch
diff2html-ui renders each line as
.d2h-code-line/.d2h-code-side-linewith an associated line number cell. Two pieces:src/dashboard/static/js/diff-viewer.js): afterDiff2HtmlUI.draw(), walk the rendered DOM and addid="L{n}"to each line number cell. Add a small "copy link" affordance on hover (chip near the line number that copies${location.pathname}${location.search}#L{n}to clipboard).#L{a}-L{b}form. Standard pattern from GitHub.location.hash, scroll the line into view, apply a.d2h-line-anchor-targetclass for highlight.Acceptance
id="L{n}"afterDiff2HtmlUI.draw()/changes/{id}#L42scrolls to line 42 and visually highlights it/changes/{id}#L42-L57highlights the rangeoutputFormat: "side-by-side"and"line-by-line"Out of scope
localStorageDependencies
None — purely client-side enhancement on top of existing diff2html-ui mount.
Related