Skip to content

Commit c38df6f

Browse files
Scope minimap hover interactions to the gutter
- Keep collapsed minimap hit targets narrow - Preserve interaction with expanded preview content
1 parent f1264c1 commit c38df6f

3 files changed

Lines changed: 54 additions & 16 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export function resolveTimelineMinimapHasPersistentGutter(viewportWidth: number)
6666

6767
export const TIMELINE_MINIMAP_HIT_STRIP_LEFT = 12;
6868
export const TIMELINE_MINIMAP_HIT_STRIP_MAX_WIDTH = 40;
69+
export const TIMELINE_MINIMAP_EXPANDED_HIT_STRIP_WIDTH = "22rem";
6970

7071
/**
7172
* The minimap overlays the viewport's left edge while the content column is
@@ -90,6 +91,18 @@ export function resolveTimelineMinimapHitStripWidth(viewportWidth: number): numb
9091
);
9192
}
9293

94+
/**
95+
* Once the preview is open, keep the full preview and the space leading to it
96+
* interactive. The collapsed strip remains gutter-capped so it cannot block
97+
* selecting message text.
98+
*/
99+
export function resolveTimelineMinimapInteractiveWidth(
100+
collapsedWidth: number,
101+
expanded: boolean,
102+
): number | string {
103+
return expanded ? TIMELINE_MINIMAP_EXPANDED_HIT_STRIP_WIDTH : collapsedWidth;
104+
}
105+
93106
function computeElapsedMs(startIso: string, endIso: string): number | null {
94107
const start = Date.parse(startIso);
95108
const end = Date.parse(endIso);

‎apps/web/src/components/chat/MessagesTimeline.test.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ describe("MessagesTimeline", () => {
226226
resolveTimelineMinimapHeightStyle,
227227
resolveTimelineMinimapHitStripWidth,
228228
resolveTimelineMinimapIndexFromPointer,
229+
resolveTimelineMinimapInteractiveWidth,
229230
resolveTimelineMinimapTopPercent,
230231
} = await import("./MessagesTimeline.logic");
231232

@@ -268,6 +269,15 @@ describe("MessagesTimeline", () => {
268269
expect(resolveTimelineMinimapHitStripWidth(1400)).toBe(40);
269270
expect(resolveTimelineMinimapHitStripWidth(0)).toBe(0);
270271
expect(resolveTimelineMinimapHitStripWidth(Number.NaN)).toBe(0);
272+
273+
// The collapsed target stays narrow, but an open preview keeps its full
274+
// 20rem width plus the 2rem offset from the minimap rail interactive.
275+
expect(resolveTimelineMinimapInteractiveWidth(0, false)).toBe(0);
276+
expect(resolveTimelineMinimapInteractiveWidth(14, false)).toBe(14);
277+
expect(resolveTimelineMinimapInteractiveWidth(40, false)).toBe(40);
278+
expect(resolveTimelineMinimapInteractiveWidth(0, true)).toBe("22rem");
279+
expect(resolveTimelineMinimapInteractiveWidth(14, true)).toBe("22rem");
280+
expect(resolveTimelineMinimapInteractiveWidth(40, true)).toBe("22rem");
271281
});
272282

273283
it("anchors a sent attachment message using its measured height", async () => {

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import {
7575
resolveTimelineMinimapHeightStyle,
7676
resolveTimelineMinimapHitStripWidth,
7777
resolveTimelineMinimapIndexFromPointer,
78+
resolveTimelineMinimapInteractiveWidth,
7879
resolveTimelineMinimapTopPercent,
7980
type StableMessagesTimelineRowsState,
8081
type MessagesTimelineRow,
@@ -604,6 +605,10 @@ function resolveTimelineRowHeight(state: TimelinePositionState, rowIndex: number
604605
return typeof height === "number" && Number.isFinite(height) ? height : null;
605606
}
606607

608+
function timelineMinimapEventTargetsPreview(target: EventTarget): boolean {
609+
return target instanceof Element && target.closest("[data-minimap-preview]") !== null;
610+
}
611+
607612
function TimelineMinimap({
608613
bottomInset,
609614
hasPersistentGutter,
@@ -697,6 +702,9 @@ function TimelineMinimap({
697702
)}
698703
onBlur={() => setActiveIndex(null)}
699704
onClick={(event) => {
705+
if (timelineMinimapEventTargetsPreview(event.target)) {
706+
return;
707+
}
700708
const nextIndex = resolveActiveIndexFromPointer(event);
701709
const nextItem = nextIndex === null ? null : (items[nextIndex] ?? null);
702710
if (nextItem) {
@@ -728,11 +736,14 @@ function TimelineMinimap({
728736
onMouseLeave={() => setActiveIndex(null)}
729737
onMouseMove={updateActiveIndexFromPointer}
730738
onMouseDown={(event) => {
739+
if (timelineMinimapEventTargetsPreview(event.target)) {
740+
return;
741+
}
731742
event.preventDefault();
732743
}}
733744
style={{
734745
height: resolveTimelineMinimapHeightStyle(items.length),
735-
width: hitStripWidth,
746+
width: resolveTimelineMinimapInteractiveWidth(hitStripWidth, activeItem !== null),
736747
}}
737748
type="button"
738749
>
@@ -770,27 +781,31 @@ function TimelineMinimap({
770781
})}
771782
{activeItem ? (
772783
<span
773-
className="pointer-events-none absolute left-8 w-80 rounded-xl border border-border/70 bg-popover/95 p-3 text-left text-popover-foreground shadow-xl shadow-black/25 backdrop-blur"
784+
className="pointer-events-auto absolute left-8 w-80 cursor-text select-text"
785+
data-minimap-preview
786+
onMouseMove={(event) => event.stopPropagation()}
774787
style={{
775788
top: `${activeTopPercent}%`,
776789
transform: `translateY(${activeTooltipTranslate})`,
777790
}}
778791
>
779-
<span className="block max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-sm font-medium leading-5">
780-
{activeItem.userText ?? "User message"}
781-
</span>
782-
{activeItem.assistantText ? (
783-
<span
784-
className="mt-1 max-h-[3.75rem] overflow-hidden text-muted-foreground text-sm leading-5"
785-
style={{
786-
display: "-webkit-box",
787-
WebkitBoxOrient: "vertical",
788-
WebkitLineClamp: 3,
789-
}}
790-
>
791-
{activeItem.assistantText}
792+
<span className="block rounded-xl border border-border/70 bg-popover/95 p-3 text-left text-popover-foreground shadow-xl shadow-black/25 backdrop-blur">
793+
<span className="block max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-sm font-medium leading-5">
794+
{activeItem.userText ?? "User message"}
792795
</span>
793-
) : null}
796+
{activeItem.assistantText ? (
797+
<span
798+
className="mt-1 max-h-[3.75rem] overflow-hidden text-muted-foreground text-sm leading-5"
799+
style={{
800+
display: "-webkit-box",
801+
WebkitBoxOrient: "vertical",
802+
WebkitLineClamp: 3,
803+
}}
804+
>
805+
{activeItem.assistantText}
806+
</span>
807+
) : null}
808+
</span>
794809
</span>
795810
) : null}
796811
</button>

0 commit comments

Comments
 (0)