From b0c2b394e0a6d03e380e19e03d9da251b4ba7300 Mon Sep 17 00:00:00 2001 From: Bojan Mojsilovic Date: Wed, 10 Jan 2024 14:05:07 +0100 Subject: [PATCH] Scroll to the top of a note if it is too long to fit the screen --- src/pages/Thread.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pages/Thread.tsx b/src/pages/Thread.tsx index a3a465b..a431b06 100644 --- a/src/pages/Thread.tsx +++ b/src/pages/Thread.tsx @@ -108,7 +108,14 @@ const Thread: Component = () => { if (!pn) return; setTimeout(() => { - pn.scrollIntoView({ block: 'end' }); + const rect = pn.getBoundingClientRect(); + const wh = window.innerHeight - 72; + + const block = rect.height < wh && parentNotes().length > 0 ? + 'end' : 'start'; + + pn.scrollIntoView({ block }); + block === 'start' && window.scrollBy({ top: -72 }); }, 100); });