mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 13:09:33 +01:00
fix(viewer): make in-document links in rendered markdown scroll to their heading
marked emits no heading ids and, with <base href="/">, a bare #section href points at the dashboard root, so [Install](#installation) in the File Viewer did nothing. The shared click delegate now resolves fragment links against the rendered document: GitHub-style slugs in data-md-anchor (never ids, so a heading cannot capture an app element), case-insensitive and percent-decoded, repeats numbered -1/-2, # = top, explicit ids supported, an unmatched fragment ignored instead of navigating. Tests: slug/assign/find unit tests (CI gate) and a real-browser test clicking links in a File Viewer document, which fails without the change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JrzFKEdBLwVfu6ev2ZscJS
This commit is contained in:
1 parent
3a0cee6b90
commit
8da4a07a60
7 files changed
+363
-1
No files matched your search
@@ -2732,6 +2732,23 @@ class CodemanApp {
|
||||
return;
|
||||
}
|
||||
|
||||
// An in-document link (`[Install](#installation)`). The browser must not follow it: with
|
||||
// `<base href="/">` a bare fragment points at the dashboard's root and would navigate the
|
||||
// app away. Resolve it inside this rendered document and scroll there (constants.js).
|
||||
// A fragment that matches nothing is simply ignored, never a navigation.
|
||||
const fragmentLink = ev.target.closest('a[href^="#"]');
|
||||
if (fragmentLink && body.contains(fragmentLink)) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
const root = fragmentLink.closest('.rv-text') || body;
|
||||
const target = window.CodemanMarkdownAnchors?.find(root, fragmentLink.getAttribute('href'));
|
||||
if (target) {
|
||||
const calm = window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches;
|
||||
target.scrollIntoView({ block: 'start', behavior: calm ? 'auto' : 'smooth' });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// A `localhost` URL in the agent's answer: from another device that can
|
||||
// only load through the server, so hand it to a proxied web tab
|
||||
// (webview-tabs.js). Every other link keeps its new-tab default.
|
||||
|
||||
Reference in new issue
Block a user