From 97c7087f6c19de79f36a883da13a88f1746f0c11 Mon Sep 17 00:00:00 2001 From: jialin Date: Mon, 16 Jun 2025 19:53:16 +0800 Subject: [PATCH] fix(style): esc hint flickering --- src/hooks/use-esc-hint.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/hooks/use-esc-hint.tsx b/src/hooks/use-esc-hint.tsx index b3606214..158ae002 100644 --- a/src/hooks/use-esc-hint.tsx +++ b/src/hooks/use-esc-hint.tsx @@ -46,14 +46,26 @@ export function useEscHint(options?: { const { styles } = useStyles(); const [visible, setVisible] = useState(false); const timeoutRef = useRef(null); + const isHintActiveRef = useRef(false); const showHintThrottled = useMemo( () => throttle( () => { - if (timeoutRef.current) clearTimeout(timeoutRef.current); + if (isHintActiveRef.current) return; + + isHintActiveRef.current = true; + setVisible(true); - timeoutRef.current = setTimeout(() => setVisible(false), 2000); + + if (timeoutRef.current) { + clearTimeout(timeoutRef.current); + } + + timeoutRef.current = setTimeout(() => { + setVisible(false); + isHintActiveRef.current = false; + }, 2000); }, throttleDelay, { @@ -67,6 +79,7 @@ export function useEscHint(options?: { useHotkeys( HotKeys.ESC, () => { + if (!enabled) return; showHintThrottled(); }, {