From 69d6d47388c874ca5c88b93d3b42bd80975574ae Mon Sep 17 00:00:00 2001 From: kahme247 <61059522+kahme247@users.noreply.github.com> Date: Mon, 26 Oct 2026 01:46:05 +0300 Subject: [PATCH 1/3] fix(chat): keep minimap tooltip aligned when the rail scrolls (#251) --- components/ChatMinimap.test.mjs | 26 +++++++++++++++++++++++++- components/ChatMinimap.tsx | 24 +++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/components/ChatMinimap.test.mjs b/components/ChatMinimap.test.mjs index 899b61d18..8d81bb123 100644 --- a/components/ChatMinimap.test.mjs +++ b/components/ChatMinimap.test.mjs @@ -8,7 +8,7 @@ const jiti = createJiti(import.meta.url, { jsx: { runtime: "automatic" }, tsconfigPaths: true, }); -const { ChatMinimap, extractPreviewText, getBarWidth } = await jiti.import("./ChatMinimap.tsx"); +const { ChatMinimap, extractPreviewText, getBarWidth, getTooltipTopPx } = await jiti.import("./ChatMinimap.tsx"); test("extractPreviewText extracts clean text from user string content", () => { const preview = extractPreviewText({ @@ -104,3 +104,27 @@ test("falls back to assistant messages when no user prompts exist", () => { assert.match(html, /aria-label="Jump to: Welcome to the agent"/); assert.match(html, /aria-label="Jump to: Ready for tasks"/); }); + +test("tooltip stays aligned with its row when the rail has scrolled (#251)", () => { + // Unscrolled: the reporter's row 0 center (6px padding + half of 18px). + assert.equal(getTooltipTopPx(0, 0), 15); + assert.equal(getTooltipTopPx(20, 0), 375); + // Scrolled: a row whose unclipped center would be 1095px (outside the + // 520px rail, as in the report for tick 60) is pulled back into the + // viewport by exactly the rail's scroll offset. + assert.equal(getTooltipTopPx(60, 594), 501); + assert.equal(getTooltipTopPx(60, 0), 1095); +}); + +test("rail rows do not shrink below the row height (#251)", () => { + const messages = Array.from({ length: 86 }, (_, i) => ({ role: "user", content: `prompt ${i}` })); + const html = renderToStaticMarkup( + React.createElement(ChatMinimap, { + messages, + scrollContainer: { current: null }, + messageRefs: { current: [] }, + }) + ); + assert.match(html, /flex-shrink:0/); + assert.match(html, /min-height:18px/); +}); diff --git a/components/ChatMinimap.tsx b/components/ChatMinimap.tsx index b19f7f7a9..f3237a7b3 100644 --- a/components/ChatMinimap.tsx +++ b/components/ChatMinimap.tsx @@ -85,10 +85,25 @@ export function getBarWidth(text: string, isActive: boolean, isHovered: boolean) const ROW_HEIGHT = 18; +/** + * Vertical center of a rail row's tooltip, in the unclipped outer + * container's coordinates. The rail is a flex column whose rows used to + * shrink below ROW_HEIGHT once the list exceeded the rail's max-height, + * so a tooltip positioned purely from the index drifted below its row + * and eventually out of view (#251). Rows are now non-shrinking (see the + * row style below), so the rail scrolls instead of compressing; the only + * correction left is the rail's own scroll offset, which is 0 while the + * rail fits and otherwise moves the visible row up by exactly that much. + */ +export function getTooltipTopPx(displayIndex: number, railScrollTop = 0): number { + return 6 + displayIndex * ROW_HEIGHT + ROW_HEIGHT / 2 - railScrollTop; +} + export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer, messageRefs }: Props) { const [activeIndex, setActiveIndex] = useState(0); const [hoveredIndex, setHoveredIndex] = useState(null); const [isRailHovered, setIsRailHovered] = useState(false); + const [railScrollTop, setRailScrollTop] = useState(0); const railRef = useRef(null); const draggingRef = useRef(false); const scrollRafRef = useRef(null); @@ -313,7 +328,7 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer const displayTooltipIndex = hoveredIndex !== null ? hoveredIndex : (isRailHovered ? activeIndex : null); const tooltipNode = displayTooltipIndex !== null ? nodes[displayTooltipIndex] : null; // Calculate unclipped vertical center position for the tooltip - const tooltipTopPx = displayTooltipIndex !== null ? 6 + displayTooltipIndex * ROW_HEIGHT + ROW_HEIGHT / 2 : 0; + const tooltipTopPx = displayTooltipIndex !== null ? getTooltipTopPx(displayTooltipIndex, railScrollTop) : 0; return (
setRailScrollTop(e.currentTarget.scrollTop)} onMouseDown={handleMouseDown} style={{ position: "relative", @@ -431,6 +447,12 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer display: "flex", alignItems: "center", height: ROW_HEIGHT, + // Rows must not shrink: with maxHeight + overflowY auto the + // rail is meant to scroll past ~25 entries, but the flex + // default (flexShrink 1) compressed every row to ~520/N + // instead, which is what broke tooltip alignment (#251). + flexShrink: 0, + minHeight: ROW_HEIGHT, paddingLeft: 6, paddingRight: 8, cursor: "pointer", From f2dd3d52b8de14c0c50d5f41106c1e984b16c0a7 Mon Sep 17 00:00:00 2001 From: kahme247 <61059522+kahme247@users.noreply.github.com> Date: Mon, 26 Oct 2026 02:05:03 +0300 Subject: [PATCH 2/3] fix(chat): map minimap drag to the scrolled row and always allow rail scroll (#251) --- components/ChatMinimap.test.mjs | 25 ++++++++++++++++++++++++- components/ChatMinimap.tsx | 25 ++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/components/ChatMinimap.test.mjs b/components/ChatMinimap.test.mjs index 8d81bb123..80b170029 100644 --- a/components/ChatMinimap.test.mjs +++ b/components/ChatMinimap.test.mjs @@ -8,7 +8,7 @@ const jiti = createJiti(import.meta.url, { jsx: { runtime: "automatic" }, tsconfigPaths: true, }); -const { ChatMinimap, extractPreviewText, getBarWidth, getTooltipTopPx } = await jiti.import("./ChatMinimap.tsx"); +const { ChatMinimap, extractPreviewText, getBarWidth, getTooltipTopPx, railIndexForPointer } = await jiti.import("./ChatMinimap.tsx"); test("extractPreviewText extracts clean text from user string content", () => { const preview = extractPreviewText({ @@ -128,3 +128,26 @@ test("rail rows do not shrink below the row height (#251)", () => { assert.match(html, /flex-shrink:0/); assert.match(html, /min-height:18px/); }); + +test("drag scrubber maps a pointer to the row actually under it when scrolled (#251 follow-up)", () => { + // Unscrolled: pointer at the center of row 20 (6 + 20*18 + 9 = 375). + assert.equal(railIndexForPointer(375, 0, 86), 20); + // Scrolled by 594px: a viewport offset of 15px lands at content + // 609, i.e. row 33 ((609 - 6) / 18 = 33.5, floored). + assert.equal(railIndexForPointer(15, 594, 86), 33); + // Clamped at both ends. + assert.equal(railIndexForPointer(-10, 0, 86), 0); + assert.equal(railIndexForPointer(9999, 0, 86), 85); +}); + +test("rail is always scrollable, even with few rows on a short viewport (#251 follow-up)", () => { + const messages = [{ role: "user", content: "only prompt" }]; + const html = renderToStaticMarkup( + React.createElement(ChatMinimap, { + messages, + scrollContainer: { current: null }, + messageRefs: { current: [] }, + }) + ); + assert.match(html, /overflow-y:auto/); +}); diff --git a/components/ChatMinimap.tsx b/components/ChatMinimap.tsx index f3237a7b3..975a3c7ff 100644 --- a/components/ChatMinimap.tsx +++ b/components/ChatMinimap.tsx @@ -99,6 +99,22 @@ export function getTooltipTopPx(displayIndex: number, railScrollTop = 0): number return 6 + displayIndex * ROW_HEIGHT + ROW_HEIGHT / 2 - railScrollTop; } +/** + * Row index under a drag pointer, in a rail whose rows are fixed-height + * and may be scrolled (#251 follow-up). The pointer's viewport offset + * inside the rail plus the rail's scroll offset gives its position in + * the rail's content, where row i starts at 6 + i * ROW_HEIGHT (6px + * top padding). The old ratio-over-visible-height mapping only worked + * while every row was visible at once, which fixed-height rows no + * longer guarantee. + */ +export function railIndexForPointer(relY: number, railScrollTop: number, nodeCount: number): number { + if (nodeCount <= 0) return 0; + const contentY = railScrollTop + relY; + const index = Math.floor((contentY - 6) / ROW_HEIGHT); + return Math.max(0, Math.min(nodeCount - 1, index)); +} + export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer, messageRefs }: Props) { const [activeIndex, setActiveIndex] = useState(0); const [hoveredIndex, setHoveredIndex] = useState(null); @@ -287,8 +303,7 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer if (!railEl) return; const rect = railEl.getBoundingClientRect(); const relY = clientY - rect.top; - const ratio = Math.max(0, Math.min(1, relY / rect.height)); - const targetIdx = Math.min(nodes.length - 1, Math.floor(ratio * nodes.length)); + const targetIdx = railIndexForPointer(relY, railEl.scrollTop, nodes.length); if (nodes[targetIdx]) { scrollToNodeRef.current(nodes[targetIdx], false); setActiveIndex(targetIdx); @@ -396,7 +411,11 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer alignItems: "flex-start", padding: "6px 6px 6px 8px", maxHeight: "min(75vh, 520px)", - overflowY: nodes.length > 25 ? "auto" : "visible", + // Always scrollable: with fixed-height rows, even 25 or fewer + // rows can exceed a short viewport's 75vh cap, and "visible" + // would then spill them out of the rail with no way to reach + // them (#251 follow-up). scrollbarWidth none keeps it clean. + overflowY: "auto", scrollbarWidth: "none", cursor: "pointer", }} From ecef3c6ce159827692026cb66e5622546dc50fcd Mon Sep 17 00:00:00 2001 From: kahme247 <61059522+kahme247@users.noreply.github.com> Date: Mon, 26 Oct 2026 02:14:22 +0300 Subject: [PATCH 3/3] fix(chat): scroll active minimap row into view on actual overflow (#251) --- components/ChatMinimap.test.mjs | 9 ++++++++- components/ChatMinimap.tsx | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/components/ChatMinimap.test.mjs b/components/ChatMinimap.test.mjs index 80b170029..d74453240 100644 --- a/components/ChatMinimap.test.mjs +++ b/components/ChatMinimap.test.mjs @@ -8,7 +8,7 @@ const jiti = createJiti(import.meta.url, { jsx: { runtime: "automatic" }, tsconfigPaths: true, }); -const { ChatMinimap, extractPreviewText, getBarWidth, getTooltipTopPx, railIndexForPointer } = await jiti.import("./ChatMinimap.tsx"); +const { ChatMinimap, extractPreviewText, getBarWidth, getTooltipTopPx, railIndexForPointer, railOverflows } = await jiti.import("./ChatMinimap.tsx"); test("extractPreviewText extracts clean text from user string content", () => { const preview = extractPreviewText({ @@ -151,3 +151,10 @@ test("rail is always scrollable, even with few rows on a short viewport (#251 fo ); assert.match(html, /overflow-y:auto/); }); + +test("active-row scroll is gated on actual rail overflow, not row count (#251 follow-up)", () => { + // 15 rows on a short viewport: content 282px > 250px viewport cap. + assert.equal(railOverflows(282, 250), true); + assert.equal(railOverflows(282, 282), false); + assert.equal(railOverflows(200, 520), false); +}); diff --git a/components/ChatMinimap.tsx b/components/ChatMinimap.tsx index 975a3c7ff..c65659b6c 100644 --- a/components/ChatMinimap.tsx +++ b/components/ChatMinimap.tsx @@ -108,6 +108,17 @@ export function getTooltipTopPx(displayIndex: number, railScrollTop = 0): number * while every row was visible at once, which fixed-height rows no * longer guarantee. */ +/** + * Whether the rail actually overflows, so the active row only gets + * scrolled into view when it could sit outside the visible rail + * (#251 follow-up). A row-count guard misses short viewports: 15 + * fixed-height rows already need 282px, more than a <376px viewport's + * 75vh cap, so the rail can overflow with far fewer than 16 rows. + */ +export function railOverflows(scrollHeight: number, clientHeight: number): boolean { + return scrollHeight > clientHeight; +} + export function railIndexForPointer(relY: number, railScrollTop: number, nodeCount: number): number { if (nodeCount <= 0) return 0; const contentY = railScrollTop + relY; @@ -285,9 +296,9 @@ export const ChatMinimap = memo(function ChatMinimap({ messages, scrollContainer return () => ro.disconnect(); }, [scrollContainer]); - // Keep active row visible within the rail when node count overflows + // Keep active row visible within the rail when the rail overflows useEffect(() => { - if (railRef.current && nodes.length > 15) { + if (railRef.current && railOverflows(railRef.current.scrollHeight, railRef.current.clientHeight)) { const activeRow = railRef.current.querySelector(`[data-index="${activeIndex}"]`) as HTMLElement | null; activeRow?.scrollIntoView({ block: "nearest", behavior: reducedMotion ? "auto" : "smooth" }); }