From 4d3e466c33b57f0e833a41eb6c21411df17bd153 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Wed, 28 Oct 2026 09:54:29 +0800 Subject: [PATCH] fix(agents): Highlight only the find matches on screen WebKit paints a highlight range inside a collapsed tool output over the text next to it. Matches in collapsed output still count, and stepping to one expands it. --- src/features/agents/SessionEditor.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/features/agents/SessionEditor.tsx b/src/features/agents/SessionEditor.tsx index a0feda8f9..919a17a68 100644 --- a/src/features/agents/SessionEditor.tsx +++ b/src/features/agents/SessionEditor.tsx @@ -293,10 +293,21 @@ function FindBar({ }, [query, streamRef]); const index = ranges.length ? Math.min(current, ranges.length - 1) : -1; + // Expanding or collapsing a tool output shows or hides its matches. + const [shown, setShown] = useState(0); useEffect(() => { - setHighlight("agent-find", ranges); - setHighlight("agent-find-current", index >= 0 ? [ranges[index]!] : []); - }, [ranges, index]); + const stream = streamRef.current; + const toggled = () => setShown((n) => n + 1); + stream?.addEventListener("toggle", toggled, true); + return () => stream?.removeEventListener("toggle", toggled, true); + }, [streamRef]); + useEffect(() => { + // Only rendered matches: WebKit paints those in collapsed
over the text next to them. + const visible = (r: Range) => r.getClientRects().length > 0; + const current = index >= 0 ? ranges[index]! : null; + setHighlight("agent-find", ranges.filter(visible)); + setHighlight("agent-find-current", current && visible(current) ? [current] : []); + }, [ranges, index, shown]); useEffect( () => () => { setHighlight("agent-find", []);