Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions apps/web/src/components/chat/MessagesTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { resolveWorkGroupScrollAnchor } from "@t3tools/client-runtime/work-log/s
import type { WorkflowOpening } from "@t3tools/client-runtime/state/subagentRuntime";
import { observeResize } from "~/lib/observeResize";
import { useStableCallback } from "~/hooks/useStableCallback";
import { createStore } from "zustand";

const NOOP_USE_ARTIFACT_TEMPLATE = () => {};
const EMPTY_PENDING_APPROVALS: ReadonlyArray<PendingApproval> = [];
Expand Down Expand Up @@ -104,7 +105,7 @@ import { type HandoffTimelineRun } from "./V2LifecycleRow";
import { TimelineSystemDivider } from "./TimelineSystemDivider";

import { forwardWheelToTimeline } from "./timelineMinimapWheel";
import { TimelineMinimap } from "./TimelineMinimap";
import { TimelineMinimap, type TimelineMinimapPosition } from "./TimelineMinimap";
import {
type TimelineRowSharedState,
type TimelineRowActivityState,
Expand Down Expand Up @@ -889,8 +890,10 @@ const ConversationTimeline = memo(function ConversationTimeline({
...(alwaysRenderKeys.length === 0 ? {} : { keys: alwaysRenderKeys }),
};
const [minimapHitStripWidth, setMinimapHitStripWidth] = useState(0);
const [minimapCurrentIndex, setMinimapCurrentIndex] = useState<number | null>(null);
const [minimapAtEnd, setMinimapAtEnd] = useState(false);
// Scrolling changes the minimap controls without changing the virtualized list.
const [minimapPosition] = useState(() =>
createStore<TimelineMinimapPosition>(() => ({ currentIndex: null, atEnd: false })),
);
const handleAnchorReady = (info: { anchorIndex: number | undefined }) => {
if (anchorMessageId !== null && info.anchorIndex !== undefined) {
onAnchorReady(anchorMessageId, info.anchorIndex);
Expand Down Expand Up @@ -962,18 +965,19 @@ const ConversationTimeline = memo(function ConversationTimeline({
scroll: scroll + currentInset,
scrollLength: state.scrollLength - currentInset,
});
const nextCurrentIndex = resolveTimelineMinimapCurrentIndex({
const currentIndex = resolveTimelineMinimapCurrentIndex({
visibleStart: currentRange.start,
visibleEnd: currentRange.end,
rowIndices: minimapRowIndices,
});
setMinimapCurrentIndex((current) =>
current === nextCurrentIndex ? current : nextCurrentIndex,
);
// The exact bottom, not the follow re-arm zone: Next can still scroll inside that zone.
setMinimapAtEnd(
const atEnd =
viewport !== undefined &&
viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight <= 1,
viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight <= 1;
minimapPosition.setState((previous) =>
previous.currentIndex === currentIndex && previous.atEnd === atEnd
? previous
: { currentIndex, atEnd },
);
});

Expand Down Expand Up @@ -1504,8 +1508,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
items={minimapItems}
hasPersistentGutter={minimapHasPersistentGutter}
hitStripWidth={minimapHitStripWidth}
currentIndex={minimapCurrentIndex}
atEnd={minimapAtEnd}
position={minimapPosition}
stripMap={minimapStripMap}
onWheel={forwardMinimapWheel}
onSelect={(item) => {
Expand Down
13 changes: 9 additions & 4 deletions apps/web/src/components/chat/TimelineMinimap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "./MessagesTimeline.logic";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { cn } from "~/lib/utils";
import { useStore, type StoreApi } from "zustand";

// A release outside the window can skip `mouseup`, so the next button-free
// `mousemove` also counts.
Expand All @@ -30,26 +31,30 @@ function onMouseButtonsReleased(onRelease: () => void): () => void {
return stop;
}

export interface TimelineMinimapPosition {
readonly currentIndex: number | null;
readonly atEnd: boolean;
}

export function TimelineMinimap({
hasPersistentGutter,
hitStripWidth,
currentIndex,
atEnd,
position,
items,
stripMap,
onWheel,
onSelect,
}: {
hasPersistentGutter: boolean;
hitStripWidth: number;
currentIndex: number | null;
atEnd: boolean;
position: StoreApi<TimelineMinimapPosition>;
items: ReadonlyArray<TimelineMinimapItem>;
stripMap: Map<string, HTMLSpanElement>;
onWheel: (event: WheelEvent) => void;
onSelect: (item: TimelineMinimapItem) => void;
}) {
const gt = useGT();
const { currentIndex, atEnd } = useStore(position);
const [activeIndex, setActiveIndex] = useState<number | null>(null);
const wheelTargetRef = (node: HTMLDivElement | null) => {
if (!node) return;
Expand Down
Loading