From dea6690a7dfa71614fe61717fbf90b32ba61382e Mon Sep 17 00:00:00 2001 From: inokawa <48897392+inokawa@users.noreply.github.com> Date: Sun, 19 May 2024 18:00:27 +0900 Subject: [PATCH] Refactor --- src/renderers/regex/index.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/renderers/regex/index.tsx b/src/renderers/regex/index.tsx index 4d313ba..93abe57 100644 --- a/src/renderers/regex/index.tsx +++ b/src/renderers/regex/index.tsx @@ -123,8 +123,8 @@ const CSSHighlighter = memo( useIsomorphicLayoutEffect(() => { const el = ref.current!.firstChild!; - const highlights = regexes.flatMap((r, i) => { - const highlight = new Highlight( + const highlights = regexes.flatMap((r) => { + return new Highlight( ...execReg(r, value).map((m) => { const start = m.index; const end = m.index + m[0]!.length; @@ -135,8 +135,10 @@ const CSSHighlighter = memo( return range; }) ); - CSS.highlights.set(createCSSHighlightID(i), highlight); - return highlight; + }); + + highlights.forEach((h, i) => { + CSS.highlights.set(createCSSHighlightID(i), h); }); return () => {