From ac66fd66dfe20c91588afaa4837fd046b32c27ee Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 24 Sep 2024 18:44:37 +0800 Subject: feat: improve focus utils * use block height to determine behavior of scrollIntoView() * change color of indicator for focused block * make indicator always visible --- src/dumbyUtils.mjs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/dumbyUtils.mjs') diff --git a/src/dumbyUtils.mjs b/src/dumbyUtils.mjs index ba0bbf8..fc9eab9 100644 --- a/src/dumbyUtils.mjs +++ b/src/dumbyUtils.mjs @@ -49,7 +49,10 @@ export function focusNextBlock(reverse = false) { const nextBlock = blocks[nextIndex] blocks.forEach(b => b.classList.remove('focus')) nextBlock?.classList?.add('focus') - nextBlock.scrollIntoView({ behavior: 'smooth', block: "nearest" }) + const scrollBlock = nextBlock.getBoundingClientRect().height > nextBlock.parentElement.getBoundingClientRect().height * 0.8 + ? 'nearest' + : 'center' + nextBlock.scrollIntoView({ behavior: 'smooth', block: scrollBlock }) } export function removeBlockFocus() { -- cgit v1.2.3-70-g09d2