From e9c3426fbe5fdc48a68d5ae2d83b6a6afd00a626 Mon Sep 17 00:00:00 2001 From: Admin Date: Thu, 2 Apr 2026 20:44:12 +0500 Subject: [PATCH] feat: scroll active chapter into view when chapter drawer opens When the mini-player chapter drawer is opened, the current chapter is now immediately scrolled into the center of the list instead of always starting from the top. Uses a Svelte action (setIfActive) to track the active chapter element and a $effect to call scrollIntoView on open. --- ui/src/routes/+layout.svelte | 44 +++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/ui/src/routes/+layout.svelte b/ui/src/routes/+layout.svelte index a00e933..c47b2e4 100644 --- a/ui/src/routes/+layout.svelte +++ b/ui/src/routes/+layout.svelte @@ -33,6 +33,21 @@ // Chapter list drawer state for the mini-player let chapterDrawerOpen = $state(false); + let activeChapterEl = $state(null); + + function setIfActive(node: HTMLElement, isActive: boolean) { + if (isActive) activeChapterEl = node; + return { + update(nowActive: boolean) { if (nowActive) activeChapterEl = node; }, + destroy() { if (activeChapterEl === node) activeChapterEl = null; } + }; + } + + $effect(() => { + if (chapterDrawerOpen && activeChapterEl) { + activeChapterEl.scrollIntoView({ block: 'center' }); + } + }); // The single