From bdf723a126a0d435233c1b4a1e3c00110bc9ea94 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sat, 21 Sep 2024 11:19:58 +0800 Subject: feat: add throttle for next map by Showcase display --- src/dumbymap.mjs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/dumbymap.mjs b/src/dumbymap.mjs index e24d130..4eb6bdf 100644 --- a/src/dumbymap.mjs +++ b/src/dumbymap.mjs @@ -308,9 +308,7 @@ export const generateMaps = async (container, callback) => { }, 300) // TODO Use UI to switch layouts - // Focus to next map with throttle - - const focusNextMap = throttle((reverse = false) => { + const focusNextMap = (reverse = false) => { // Decide how many candidates could be focused const selector = '.map-container, [data-placeholder]' const candidates = Array.from(htmlHolder.querySelectorAll(selector)) @@ -331,13 +329,16 @@ export const generateMaps = async (container, callback) => { : 0 const nextFocus = candidates.at(nextIndex) nextFocus.setAttribute('data-focus', "true") - }, 300) + } + const focusDelay = () => getComputedStyle(showcase).display === 'none' ? 50 : 300 + const focusNextMapWithThrottle = throttle(focusNextMap, focusDelay) const originalKeyDown = document.onkeydown document.onkeydown = (e) => { const event = originalKeyDown(e) if (!event) return + // Switch to next layout if (event.key === 'x' && container.querySelector('.map-container')) { e.preventDefault() switchToNextLayout() -- cgit v1.2.3-70-g09d2