mirror of
https://github.com/zadam/trilium.git
synced 2025-11-07 23:18:59 +01:00
fix(share): TOC indicator no longer working due to layout changes
This commit is contained in:
parent
413b16b51c
commit
78f067965f
@ -9,8 +9,9 @@
|
||||
* entry as the user scrolls.
|
||||
*/
|
||||
export default function setupToC() {
|
||||
const container = document.getElementById("right-pane");
|
||||
const toc = document.getElementById("toc");
|
||||
if (!toc) return;
|
||||
if (!toc || !container) return;
|
||||
|
||||
// Get all relevant elements
|
||||
const sections = document.getElementById("content")!.querySelectorAll("h2, h3, h4, h5, h6");
|
||||
@ -32,8 +33,8 @@ export default function setupToC() {
|
||||
function changeLinkState() {
|
||||
let index = sections.length;
|
||||
|
||||
// Work backkwards to find the first matching section
|
||||
while (--index && window.scrollY + 50 < (sections[index] as HTMLElement).offsetTop) {} // eslint-disable-line no-empty
|
||||
// Work backwards to find the first matching section
|
||||
while (--index && container!.scrollTop + 50 < (sections[index] as HTMLElement).offsetTop) {} // eslint-disable-line no-empty
|
||||
|
||||
// Update the "active" item in ToC
|
||||
links.forEach((link) => link.classList.remove("active"));
|
||||
@ -42,5 +43,5 @@ export default function setupToC() {
|
||||
|
||||
// Initial render
|
||||
changeLinkState();
|
||||
window.addEventListener("scroll", changeLinkState);
|
||||
container.addEventListener("scroll", changeLinkState);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user