From e65243cfa31161636ab4f5e992f5f63c5cdb7efe Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Sun, 10 Nov 2024 15:30:52 -0800 Subject: [PATCH] find widget cleanup p3 --- gui/src/components/find/FindWidget.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gui/src/components/find/FindWidget.tsx b/gui/src/components/find/FindWidget.tsx index 8de296017..a113c7ea0 100644 --- a/gui/src/components/find/FindWidget.tsx +++ b/gui/src/components/find/FindWidget.tsx @@ -89,7 +89,7 @@ export const useFindWidget = (searchRef: RefObject) => { const [useRegex, setUseRegex] = useState(false); const [matches, setMatches] = useState([]); - const [currentMatch, setCurrentMatch] = useState(); + const [currentMatch, setCurrentMatch] = useState(undefined); // Navigating between search results // The "current" search result is highlighted a different color @@ -103,14 +103,14 @@ export const useFindWidget = (searchRef: RefObject) => { }, [searchRef.current]) const nextMatch = useCallback(() => { - if (matches.length === 0) return + if (!currentMatch || (matches.length === 0)) return const newIndex = (currentMatch.index + 1) % matches.length; const newMatch = matches[newIndex] scrollToMatch(newMatch) }, [scrollToMatch, currentMatch, matches]) const previousMatch = useCallback(() => { - if (matches.length === 0) return + if (!currentMatch || (matches.length === 0)) return const newIndex = currentMatch.index === 0 ? matches.length - 1 : currentMatch.index - 1 const newMatch = matches[newIndex] scrollToMatch(newMatch) @@ -326,7 +326,7 @@ export const useFindWidget = (searchRef: RefObject) => { // Generate the highlight overlay elements const highlights = useMemo(() => { - return matches.map(match => ) + return matches.map(match => ) }, [matches, currentMatch]) return {