From 06489839e9a3b6e234d89b2c5a7d4eebf005fb90 Mon Sep 17 00:00:00 2001 From: Richard Ginzburg Date: Fri, 28 Aug 2026 11:39:05 +0300 Subject: [PATCH 1/2] fix: minimap tooltip transparency and chat text overlap - Tooltip opacity raised to fully opaque; opaque backdrop panel with project Tooltip treatment (bg-panel, border, radius-control, shadow-pop) - Tooltips interactive: click to scroll to message, hover highlights - Gap between minimap strip and tooltip panel bridged - Scrollable list panel when tooltips exceed minimap height, with auto-follow via effect + data-node-index query - React hook ordering: all hooks before early return - Chat column maxWidth constrained on narrow viewports so minimap never covers text; MINIMAP_WIDTH shared in lib/chat-layout.ts Fixes #22, fixes #23 --- components/ChatMinimap.tsx | 154 +++++++++++++++++++++++++++++++------ components/ChatWindow.tsx | 10 ++- lib/chat-layout.ts | 5 ++ 3 files changed, 143 insertions(+), 26 deletions(-) diff --git a/components/ChatMinimap.tsx b/components/ChatMinimap.tsx index f33c86772..21174edb9 100644 --- a/components/ChatMinimap.tsx +++ b/components/ChatMinimap.tsx @@ -2,6 +2,7 @@ import { memo, useEffect, useRef, useState, useCallback, useMemo, RefObject } from "react"; import type { AgentMessage, AssistantMessage, TextContent } from "@/lib/types"; +import { MINIMAP_WIDTH } from "@/lib/chat-layout"; interface Props { messages: AgentMessage[]; @@ -9,7 +10,6 @@ interface Props { messageRefs: RefObject<(HTMLDivElement | null)[]>; } -const MINIMAP_WIDTH = 36; function getMessagePreview(msg: AgentMessage | Partial): string { if (msg.role === "user") { @@ -70,9 +70,11 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer const [nodes, setNodes] = useState([]); const [minimapHovered, setMinimapHovered] = useState(false); const [mouseYRatio, setMouseYRatio] = useState(null); + const [hoveredTooltipIndex, setHoveredTooltipIndex] = useState(null); const draggingRef = useRef(false); const dragListenersRef = useRef<{ onMove: (ev: MouseEvent) => void; onUp: () => void } | null>(null); const containerRef = useRef(null); + const overflowPanelRef = useRef(null); // RAF gate for mousemove so a pixel-level pointer event doesn't re-render // the whole minimap (every node + tooltip) on every frame. const mouseMoveRafRef = useRef(null); @@ -284,6 +286,7 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer const TOOLTIP_HEIGHT = 22; const TOOLTIP_GAP = 2; const minimapHeightPx = containerRef.current?.clientHeight ?? 600; + const tooltipListOverflows = nodes.length * (TOOLTIP_HEIGHT + TOOLTIP_GAP) > minimapHeightPx; // Per-node colors and previews are pure functions of each node's message; // memoize so they aren't recomputed on every scroll/mousemove re-render. @@ -291,7 +294,7 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer const nodePreviews = useMemo(() => nodes.map((node) => getMessagePreview(node.msg)), [nodes]); const tooltipPositions = useMemo(() => { - if (!minimapHovered || nodes.length === 0) return []; + if (!minimapHovered || nodes.length === 0 || tooltipListOverflows) return []; // Initial positions: centered on the dot const positions = nodes.map((node) => Math.round(node.topRatio * minimapHeightPx - TOOLTIP_HEIGHT / 2) @@ -312,26 +315,40 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer positions[i] = Math.max(0, Math.min(minimapHeightPx - TOOLTIP_HEIGHT, positions[i])); } return positions; - }, [minimapHovered, nodes, minimapHeightPx]); + }, [minimapHovered, nodes, minimapHeightPx, tooltipListOverflows]); - if (!visible) return null; - - const viewportBoxTop = scrollRatio * (1 - viewportRatio) * 100; - const viewportBoxHeight = viewportRatio * 100; - - // Find the node closest to the current mouse position - const nearestIndex = mouseYRatio !== null && nodes.length > 0 + // Find the node closest to the current mouse position; direct tooltip + // hover takes precedence (collision-free layout shifts tooltip positions + // away from their node's scroll ratio, so Y-distance is wrong there). + const computedNearest = mouseYRatio !== null && nodes.length > 0 ? nodes.reduce((best, node) => { return Math.abs(node.topRatio - mouseYRatio) < Math.abs(nodes[best].topRatio - mouseYRatio) ? node.index : best; }, 0) : null; + const nearestIndex = hoveredTooltipIndex ?? computedNearest; + + // Auto-scroll the overflow tooltip panel to keep the minimap-driven + // selection visible. Skipped when the user is directly hovering over the + // panel (hoveredTooltipIndex !== null) to avoid fighting manual scrolling. + useEffect(() => { + if (computedNearest === null || hoveredTooltipIndex !== null) return; + const panel = overflowPanelRef.current; + if (!panel) return; + const row = panel.querySelector(`[data-node-index="${computedNearest}"]`) as HTMLElement | null; + row?.scrollIntoView({ block: "nearest" }); + }, [computedNearest, hoveredTooltipIndex]); + + if (!visible) return null; + + const viewportBoxTop = scrollRatio * (1 - viewportRatio) * 100; + const viewportBoxHeight = viewportRatio * 100; return (
setMinimapHovered(true)} - onMouseLeave={() => { setMinimapHovered(false); setMouseYRatio(null); }} + onMouseLeave={() => { setMinimapHovered(false); setMouseYRatio(null); setHoveredTooltipIndex(null); }} onMouseMove={handleMinimapMouseMove} style={{ width: MINIMAP_WIDTH, @@ -417,9 +434,95 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer zIndex: 0, }} /> - - {/* Tooltips for all nodes, collision-free positions */} - {minimapHovered && nodes.map((node, i) => { + {/* Tooltip panel: scrollable list when overflowing, absolute-positioned when fits */} + {minimapHovered && nodes.length > 0 && tooltipListOverflows && ( +
e.stopPropagation()} + style={{ + position: "absolute", + top: 0, + bottom: 0, + right: "100%", + width: 206, + background: "var(--bg-panel)", + border: "1px solid var(--border)", + borderRadius: "var(--radius-control)", + boxShadow: "var(--shadow-pop)", + zIndex: 99, + pointerEvents: "auto", + overflowY: "auto", + overflowX: "hidden", + }} + > + {nodes.map((node) => { + const preview = nodePreviews[node.index] ?? getMessagePreview(node.msg); + const color = nodeColors[node.index] ?? getNodeColor(node.msg); + const isNearest = nearestIndex === node.index; + if (!preview) return null; + return ( +
setHoveredTooltipIndex(node.index)} + onMouseLeave={() => setHoveredTooltipIndex(null)} + onClick={(e) => { + e.stopPropagation(); + const el = scrollContainer.current; + if (!el) return; + el.scrollTop = node.topRatio * el.scrollHeight; + }} + style={{ + padding: "2px 7px", + borderLeft: `2px solid ${color.border}`, + background: isNearest ? "var(--bg-hover)" : "transparent", + cursor: "pointer", + transition: "background var(--dur-fast) var(--ease-out-warm)", + }} + > +
+ {preview} +
+
+ ); + })} +
+ )} + {minimapHovered && tooltipPositions.length > 0 && (() => { + // Opaque backdrop spanning first to last tooltip; width includes the + // 6px gutter so the mouse can't fall through the gap between the + // minimap strip and the tooltip panel. + const firstTop = tooltipPositions[0]; + const lastBottom = tooltipPositions[tooltipPositions.length - 1] + TOOLTIP_HEIGHT; + return ( +
e.stopPropagation()} + style={{ + position: "absolute", + top: firstTop - 4, + right: "100%", + width: 206, + height: lastBottom - firstTop + 8, + background: "var(--bg-panel)", + border: "1px solid var(--border)", + borderRadius: "var(--radius-control)", + boxShadow: "var(--shadow-pop)", + zIndex: 99, + pointerEvents: "auto", + }} + /> + ); + })()} + {minimapHovered && !tooltipListOverflows && nodes.map((node, i) => { const preview = nodePreviews[i] ?? getMessagePreview(node.msg); const color = nodeColors[i] ?? getNodeColor(node.msg); const isNearest = nearestIndex === node.index; @@ -427,23 +530,28 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer return (
e.stopPropagation()} + onMouseEnter={() => setHoveredTooltipIndex(node.index)} + onMouseLeave={() => setHoveredTooltipIndex(null)} + onClick={(e) => { + e.stopPropagation(); + const el = scrollContainer.current; + if (!el) return; + el.scrollTop = node.topRatio * el.scrollHeight; + }} style={{ position: "absolute", top: tooltipPositions[i], right: "100%", - marginRight: 6, - background: "var(--bg)", - borderTop: `1px solid ${isNearest ? color.border : "var(--border)"}`, - borderRight: `1px solid ${isNearest ? color.border : "var(--border)"}`, - borderBottom: `1px solid ${isNearest ? color.border : "var(--border)"}`, + marginRight: 3, + background: isNearest ? "var(--bg-hover)" : "var(--bg-panel)", borderLeft: `2px solid ${color.border}`, - borderRadius: 4, + borderRadius: 2, padding: "2px 7px", width: 200, zIndex: 100, - pointerEvents: "none", - opacity: isNearest ? 1 : 0.45, - transition: "top var(--dur-fast) var(--ease-out-warm), opacity var(--dur-fast) var(--ease-out-warm)", + cursor: "pointer", + transition: "top var(--dur-fast) var(--ease-out-warm), background var(--dur-fast) var(--ease-out-warm)", }} >
-
+
@@ -1008,7 +1012,7 @@ export function ChatWindow({ session, newSessionCwd, toolCallsDefaultCollapsed = users need the scrollbar (Chrome's overlay scrollbar still shows). */}
-
+
diff --git a/lib/chat-layout.ts b/lib/chat-layout.ts index 4600d32c8..89844a1db 100644 --- a/lib/chat-layout.ts +++ b/lib/chat-layout.ts @@ -2,3 +2,8 @@ * Kept in one place so the message list, notices shelf, empty state, and * composer cannot drift apart. */ export const CHAT_COLUMN_MAX_WIDTH = 960; + +/** Width of the minimap strip overlaid on the right edge of the chat scroll + * area (desktop only). Used to constrain the centered transcript column so + * it never extends under the minimap on narrow viewports. */ +export const MINIMAP_WIDTH = 36; From 1d46ba67169099404c9e9aa54029d8d57eb926fc Mon Sep 17 00:00:00 2001 From: Khaled Ahmed <61059522+Harvi8@users.noreply.github.com> Date: Fri, 28 Aug 2026 12:09:04 +0300 Subject: [PATCH 2/2] fix(minimap): correct tooltip indexing, scroll math and height tracking - Fix overflow panel using node.index as array index for previews/colors (always fell back to recompute, bypassed memoization) - Fix click-to-scroll: use (scrollHeight - clientHeight) instead of scrollHeight - Guard scrollToMinimapRatio against NaN when viewportRatio ~=1 (1 - ratio < 1e-6) - Capture fresh minimap rect on drag instead of stale mousedown rect - Make minimapHeightPx reactive via ResizeObserver/state instead of ref read during render (was stale 600px until next hover) --- components/ChatMinimap.tsx | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/components/ChatMinimap.tsx b/components/ChatMinimap.tsx index 21174edb9..9971636ce 100644 --- a/components/ChatMinimap.tsx +++ b/components/ChatMinimap.tsx @@ -75,6 +75,7 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer const dragListenersRef = useRef<{ onMove: (ev: MouseEvent) => void; onUp: () => void } | null>(null); const containerRef = useRef(null); const overflowPanelRef = useRef(null); + const [minimapHeightPx, setMinimapHeightPx] = useState(600); // RAF gate for mousemove so a pixel-level pointer event doesn't re-render // the whole minimap (every node + tooltip) on every frame. const mouseMoveRafRef = useRef(null); @@ -218,8 +219,10 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer if (!el) return; const scrollable = el.scrollHeight - el.clientHeight; if (scrollable <= 0) return; - const clamped = Math.max(0, Math.min(1 - viewportRatio, viewportTopRatio)); - el.scrollTop = (clamped / (1 - viewportRatio)) * scrollable; + const denom = 1 - viewportRatio; + if (denom < 1e-6) return; + const clamped = Math.max(0, Math.min(denom, viewportTopRatio)); + el.scrollTop = (clamped / denom) * scrollable; }, [scrollContainer, viewportRatio]); // Coalesce mousemove updates to one per animation frame: writing state on @@ -254,7 +257,9 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer const onMove = (ev: MouseEvent) => { if (!draggingRef.current) return; - const r = (ev.clientY - rect.top) / rect.height; + const curRect = containerRef.current?.getBoundingClientRect(); + if (!curRect) return; + const r = (ev.clientY - curRect.top) / curRect.height; scrollToMinimapRatio(r - offset); }; const onUp = () => { @@ -282,10 +287,20 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer + // Keep minimap height in state so tooltip layout updates on resize (ref reads don't trigger renders) + useEffect(() => { + const el = containerRef.current; + if (!el) return; + const update = () => setMinimapHeightPx(el.clientHeight || 600); + update(); + const ro = new ResizeObserver(update); + ro.observe(el); + return () => ro.disconnect(); + }, [visible]); + // Compute collision-free tooltip positions for all nodes const TOOLTIP_HEIGHT = 22; const TOOLTIP_GAP = 2; - const minimapHeightPx = containerRef.current?.clientHeight ?? 600; const tooltipListOverflows = nodes.length * (TOOLTIP_HEIGHT + TOOLTIP_GAP) > minimapHeightPx; // Per-node colors and previews are pure functions of each node's message; @@ -455,9 +470,9 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer overflowX: "hidden", }} > - {nodes.map((node) => { - const preview = nodePreviews[node.index] ?? getMessagePreview(node.msg); - const color = nodeColors[node.index] ?? getNodeColor(node.msg); + {nodes.map((node, i) => { + const preview = nodePreviews[i] ?? getMessagePreview(node.msg); + const color = nodeColors[i] ?? getNodeColor(node.msg); const isNearest = nearestIndex === node.index; if (!preview) return null; return ( @@ -470,7 +485,8 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer e.stopPropagation(); const el = scrollContainer.current; if (!el) return; - el.scrollTop = node.topRatio * el.scrollHeight; + const max = el.scrollHeight - el.clientHeight; + el.scrollTop = node.topRatio * Math.max(0, max); }} style={{ padding: "2px 7px", @@ -537,7 +553,8 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer e.stopPropagation(); const el = scrollContainer.current; if (!el) return; - el.scrollTop = node.topRatio * el.scrollHeight; + const max = el.scrollHeight - el.clientHeight; + el.scrollTop = node.topRatio * Math.max(0, max); }} style={{ position: "absolute",