mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-19 04:39:33 +01:00
Merge pull request #563: fix(viewer): make in-document links in rendered markdown scroll to their heading
This commit is contained in:
commit
e6deab98a6
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