Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

DiffPanel.tsx

647 lines24.6 KB

1import { parsePatchFiles } from "@pierre/diffs";
2import { FileDiff, type FileDiffMetadata, Virtualizer } from "@pierre/diffs/react";
3import { useQuery } from "@tanstack/react-query";
4import { useNavigate, useParams, useSearch } from "@tanstack/react-router";
5import { ThreadId, type TurnId } from "@t3tools/contracts";
6import {
7 ChevronLeftIcon,
8 ChevronRightIcon,
9 Columns2Icon,
10 Rows3Icon,
11 TextWrapIcon,
12} from "lucide-react";
13import {
14 type WheelEvent as ReactWheelEvent,
15 useCallback,
16 useEffect,
17 useMemo,
18 useRef,
19 useState,
20} from "react";
21import { openInPreferredEditor } from "../editorPreferences";
22import { gitBranchesQueryOptions } from "~/lib/gitReactQuery";
23import { checkpointDiffQueryOptions } from "~/lib/providerReactQuery";
24import { cn } from "~/lib/utils";
25import { readNativeApi } from "../nativeApi";
26import { resolvePathLinkTarget } from "../terminal-links";
27import { parseDiffRouteSearch, stripDiffSearchParams } from "../diffRouteSearch";
28import { useTheme } from "../hooks/useTheme";
29import { buildPatchCacheKey } from "../lib/diffRendering";
30import { resolveDiffThemeName } from "../lib/diffRendering";
31import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
32import { useStore } from "../store";
33import { useSettings } from "../hooks/useSettings";
34import { formatShortTimestamp } from "../timestampFormat";
35import { DiffPanelLoadingState, DiffPanelShell, type DiffPanelMode } from "./DiffPanelShell";
36import { ToggleGroup, Toggle } from "./ui/toggle-group";
37​
38type DiffRenderMode = "stacked" | "split";
39type DiffThemeType = "light" | "dark";
40​
41const DIFF_PANEL_UNSAFE_CSS = `
42[data-diffs-header],
43[data-diff],
44[data-file],
45[data-error-wrapper],
46[data-virtualizer-buffer] {
47 --diffs-bg: color-mix(in srgb, var(--card) 90%, var(--background)) !important;
48 --diffs-light-bg: color-mix(in srgb, var(--card) 90%, var(--background)) !important;
49 --diffs-dark-bg: color-mix(in srgb, var(--card) 90%, var(--background)) !important;
50 --diffs-token-light-bg: transparent;
51 --diffs-token-dark-bg: transparent;
52​
53 --diffs-bg-context-override: color-mix(in srgb, var(--background) 97%, var(--foreground));
54 --diffs-bg-hover-override: color-mix(in srgb, var(--background) 94%, var(--foreground));
55 --diffs-bg-separator-override: color-mix(in srgb, var(--background) 95%, var(--foreground));
56 --diffs-bg-buffer-override: color-mix(in srgb, var(--background) 90%, var(--foreground));
57​
58 --diffs-bg-addition-override: color-mix(in srgb, var(--background) 92%, var(--success));
59 --diffs-bg-addition-number-override: color-mix(in srgb, var(--background) 88%, var(--success));
60 --diffs-bg-addition-hover-override: color-mix(in srgb, var(--background) 85%, var(--success));
61 --diffs-bg-addition-emphasis-override: color-mix(in srgb, var(--background) 80%, var(--success));
62​
63 --diffs-bg-deletion-override: color-mix(in srgb, var(--background) 92%, var(--destructive));
64 --diffs-bg-deletion-number-override: color-mix(in srgb, var(--background) 88%, var(--destructive));
65 --diffs-bg-deletion-hover-override: color-mix(in srgb, var(--background) 85%, var(--destructive));
66 --diffs-bg-deletion-emphasis-override: color-mix(
67 in srgb,
68 var(--background) 80%,
69 var(--destructive)
70 );
71​
72 background-color: var(--diffs-bg) !important;
74​
75[data-file-info] {
76 background-color: color-mix(in srgb, var(--card) 94%, var(--foreground)) !important;
77 border-block-color: var(--border) !important;
78 color: var(--foreground) !important;
80​
81[data-diffs-header] {
82 position: sticky !important;
83 top: 0;
84 z-index: 4;
85 background-color: color-mix(in srgb, var(--card) 94%, var(--foreground)) !important;
86 border-bottom: 1px solid var(--border) !important;
88​
89[data-title] {
90 cursor: pointer;
91 transition:
92 color 120ms ease,
93 text-decoration-color 120ms ease;
94 text-decoration: underline;
95 text-decoration-color: transparent;
96 text-underline-offset: 2px;
98​
99[data-title]:hover {
100 color: color-mix(in srgb, var(--foreground) 84%, var(--primary)) !important;
101 text-decoration-color: currentColor;
103`;
104​
105type RenderablePatch =
106 | {
107 kind: "files";
108 files: FileDiffMetadata[];
109 }
110 | {
111 kind: "raw";
112 text: string;
113 reason: string;
114 };
115​
116function getRenderablePatch(
117 patch: string | undefined,
118 cacheScope = "diff-panel",
119): RenderablePatch | null {
120 if (!patch) return null;
121 const normalizedPatch = patch.trim();
122 if (normalizedPatch.length === 0) return null;
123​
124 try {
125 const parsedPatches = parsePatchFiles(
126 normalizedPatch,
127 buildPatchCacheKey(normalizedPatch, cacheScope),
128 );
129 const files = parsedPatches.flatMap((parsedPatch) => parsedPatch.files);
130 if (files.length > 0) {
131 return { kind: "files", files };
132 }
133​
134 return {
135 kind: "raw",
136 text: normalizedPatch,
137 reason: "Unsupported diff format. Showing raw patch.",
138 };
139 } catch {
140 return {
141 kind: "raw",
142 text: normalizedPatch,
143 reason: "Failed to parse patch. Showing raw patch.",
144 };
145 }
147​
148function resolveFileDiffPath(fileDiff: FileDiffMetadata): string {
149 const raw = fileDiff.name ?? fileDiff.prevName ?? "";
150 if (raw.startsWith("a/") || raw.startsWith("b/")) {
151 return raw.slice(2);
152 }
153 return raw;
155​
156function buildFileDiffRenderKey(fileDiff: FileDiffMetadata): string {
157 return fileDiff.cacheKey ?? `${fileDiff.prevName ?? "none"}:${fileDiff.name}`;
159​
160interface DiffPanelProps {
161 mode?: DiffPanelMode;
163​
164export { DiffWorkerPoolProvider } from "./DiffWorkerPoolProvider";
165​
166export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
167 const navigate = useNavigate();
168 const { resolvedTheme } = useTheme();
169 const settings = useSettings();
170 const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
171 const [diffWordWrap, setDiffWordWrap] = useState(settings.diffWordWrap);
172 const patchViewportRef = useRef<HTMLDivElement>(null);
173 const turnStripRef = useRef<HTMLDivElement>(null);
174 const previousDiffOpenRef = useRef(false);
175 const [canScrollTurnStripLeft, setCanScrollTurnStripLeft] = useState(false);
176 const [canScrollTurnStripRight, setCanScrollTurnStripRight] = useState(false);
177 const routeThreadId = useParams({
178 strict: false,
179 select: (params) => (params.threadId ? ThreadId.makeUnsafe(params.threadId) : null),
180 });
181 const diffSearch = useSearch({ strict: false, select: (search) => parseDiffRouteSearch(search) });
182 const diffOpen = diffSearch.diff === "1";
183 const activeThreadId = routeThreadId;
184 const activeThread = useStore((store) =>
185 activeThreadId ? store.threads.find((thread) => thread.id === activeThreadId) : undefined,
186 );
187 const activeProjectId = activeThread?.projectId ?? null;
188 const activeProject = useStore((store) =>
189 activeProjectId ? store.projects.find((project) => project.id === activeProjectId) : undefined,
190 );
191 const activeCwd = activeThread?.worktreePath ?? activeProject?.cwd;
192 const gitBranchesQuery = useQuery(gitBranchesQueryOptions(activeCwd ?? null));
193 const isGitRepo = gitBranchesQuery.data?.isRepo ?? true;
194 const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =
195 useTurnDiffSummaries(activeThread);
196 const orderedTurnDiffSummaries = useMemo(
197 () =>
198 [...turnDiffSummaries].toSorted((left, right) => {
199 const leftTurnCount =
200 left.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[left.turnId] ?? 0;
201 const rightTurnCount =
202 right.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[right.turnId] ?? 0;
203 if (leftTurnCount !== rightTurnCount) {
204 return rightTurnCount - leftTurnCount;
205 }
206 return right.completedAt.localeCompare(left.completedAt);
207 }),
208 [inferredCheckpointTurnCountByTurnId, turnDiffSummaries],
209 );
210​
211 const selectedTurnId = diffSearch.diffTurnId ?? null;
212 const selectedFilePath = selectedTurnId !== null ? (diffSearch.diffFilePath ?? null) : null;
213 const selectedTurn =
214 selectedTurnId === null
215 ? undefined
216 : (orderedTurnDiffSummaries.find((summary) => summary.turnId === selectedTurnId) ??
217 orderedTurnDiffSummaries[0]);
218 const selectedCheckpointTurnCount =
219 selectedTurn &&
220 (selectedTurn.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[selectedTurn.turnId]);
221 const selectedCheckpointRange = useMemo(
222 () =>
223 typeof selectedCheckpointTurnCount === "number"
224 ? {
225 fromTurnCount: Math.max(0, selectedCheckpointTurnCount - 1),
226 toTurnCount: selectedCheckpointTurnCount,
227 }
228 : null,
229 [selectedCheckpointTurnCount],
230 );
231 const conversationCheckpointTurnCount = useMemo(() => {
232 const turnCounts = orderedTurnDiffSummaries
233 .map(
234 (summary) =>
235 summary.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[summary.turnId],
236 )
237 .filter((value): value is number => typeof value === "number");
238 if (turnCounts.length === 0) {
239 return undefined;
240 }
241 const latest = Math.max(...turnCounts);
242 return latest > 0 ? latest : undefined;
243 }, [inferredCheckpointTurnCountByTurnId, orderedTurnDiffSummaries]);
244 const conversationCheckpointRange = useMemo(
245 () =>
246 !selectedTurn && typeof conversationCheckpointTurnCount === "number"
247 ? {
248 fromTurnCount: 0,
249 toTurnCount: conversationCheckpointTurnCount,
250 }
251 : null,
252 [conversationCheckpointTurnCount, selectedTurn],
253 );
254 const activeCheckpointRange = selectedTurn
255 ? selectedCheckpointRange
256 : conversationCheckpointRange;
257 const conversationCacheScope = useMemo(() => {
258 if (selectedTurn || orderedTurnDiffSummaries.length === 0) {
259 return null;
260 }
261 return `conversation:${orderedTurnDiffSummaries.map((summary) => summary.turnId).join(",")}`;
262 }, [orderedTurnDiffSummaries, selectedTurn]);
263 const activeCheckpointDiffQuery = useQuery(
264 checkpointDiffQueryOptions({
265 threadId: activeThreadId,
266 fromTurnCount: activeCheckpointRange?.fromTurnCount ?? null,
267 toTurnCount: activeCheckpointRange?.toTurnCount ?? null,
268 cacheScope: selectedTurn ? `turn:${selectedTurn.turnId}` : conversationCacheScope,
269 enabled: isGitRepo,
270 }),
271 );
272 const selectedTurnCheckpointDiff = selectedTurn
273 ? activeCheckpointDiffQuery.data?.diff
274 : undefined;
275 const conversationCheckpointDiff = selectedTurn
276 ? undefined
277 : activeCheckpointDiffQuery.data?.diff;
278 const isLoadingCheckpointDiff = activeCheckpointDiffQuery.isLoading;
279 const checkpointDiffError =
280 activeCheckpointDiffQuery.error instanceof Error
281 ? activeCheckpointDiffQuery.error.message
282 : activeCheckpointDiffQuery.error
283 ? "Failed to load checkpoint diff."
284 : null;
285​
286 const selectedPatch = selectedTurn ? selectedTurnCheckpointDiff : conversationCheckpointDiff;
287 const hasResolvedPatch = typeof selectedPatch === "string";
288 const hasNoNetChanges = hasResolvedPatch && selectedPatch.trim().length === 0;
289 const renderablePatch = useMemo(
290 () => getRenderablePatch(selectedPatch, `diff-panel:${resolvedTheme}`),
291 [resolvedTheme, selectedPatch],
292 );
293 const renderableFiles = useMemo(() => {
294 if (!renderablePatch || renderablePatch.kind !== "files") {
295 return [];
296 }
297 return renderablePatch.files.toSorted((left, right) =>
298 resolveFileDiffPath(left).localeCompare(resolveFileDiffPath(right), undefined, {
299 numeric: true,
300 sensitivity: "base",
301 }),
302 );
303 }, [renderablePatch]);
304​
305 useEffect(() => {
306 if (diffOpen && !previousDiffOpenRef.current) {
307 setDiffWordWrap(settings.diffWordWrap);
308 }
309 previousDiffOpenRef.current = diffOpen;
310 }, [diffOpen, settings.diffWordWrap]);
311​
312 useEffect(() => {
313 if (!selectedFilePath || !patchViewportRef.current) {
314 return;
315 }
316 const target = Array.from(
317 patchViewportRef.current.querySelectorAll<HTMLElement>("[data-diff-file-path]"),
318 ).find((element) => element.dataset.diffFilePath === selectedFilePath);
319 target?.scrollIntoView({ block: "nearest" });
320 }, [selectedFilePath, renderableFiles]);
321​
322 const openDiffFileInEditor = useCallback(
323 (filePath: string) => {
324 const api = readNativeApi();
325 if (!api) return;
326 const targetPath = activeCwd ? resolvePathLinkTarget(filePath, activeCwd) : filePath;
327 void openInPreferredEditor(api, targetPath).catch((error) => {
328 console.warn("Failed to open diff file in editor.", error);
329 });
330 },
331 [activeCwd],
332 );
333​
334 const selectTurn = (turnId: TurnId) => {
335 if (!activeThread) return;
336 void navigate({
337 to: "/$threadId",
338 params: { threadId: activeThread.id },
339 search: (previous) => {
340 const rest = stripDiffSearchParams(previous);
341 return { ...rest, diff: "1", diffTurnId: turnId };
342 },
343 });
344 };
345 const selectWholeConversation = () => {
346 if (!activeThread) return;
347 void navigate({
348 to: "/$threadId",
349 params: { threadId: activeThread.id },
350 search: (previous) => {
351 const rest = stripDiffSearchParams(previous);
352 return { ...rest, diff: "1" };
353 },
354 });
355 };
356 const updateTurnStripScrollState = useCallback(() => {
357 const element = turnStripRef.current;
358 if (!element) {
359 setCanScrollTurnStripLeft(false);
360 setCanScrollTurnStripRight(false);
361 return;
362 }
363​
364 const maxScrollLeft = Math.max(0, element.scrollWidth - element.clientWidth);
365 setCanScrollTurnStripLeft(element.scrollLeft > 4);
366 setCanScrollTurnStripRight(element.scrollLeft < maxScrollLeft - 4);
367 }, []);
368 const scrollTurnStripBy = useCallback((offset: number) => {
369 const element = turnStripRef.current;
370 if (!element) return;
371 element.scrollBy({ left: offset, behavior: "smooth" });
372 }, []);
373 const onTurnStripWheel = useCallback((event: ReactWheelEvent<HTMLDivElement>) => {
374 const element = turnStripRef.current;
375 if (!element) return;
376 if (element.scrollWidth <= element.clientWidth + 1) return;
377 if (Math.abs(event.deltaY) <= Math.abs(event.deltaX)) return;
378​
379 event.preventDefault();
380 element.scrollBy({ left: event.deltaY, behavior: "auto" });
381 }, []);
382​
383 useEffect(() => {
384 const element = turnStripRef.current;
385 if (!element) return;
386​
387 const frameId = window.requestAnimationFrame(() => updateTurnStripScrollState());
388 const onScroll = () => updateTurnStripScrollState();
389​
390 element.addEventListener("scroll", onScroll, { passive: true });
391​
392 const resizeObserver = new ResizeObserver(() => updateTurnStripScrollState());
393 resizeObserver.observe(element);
394​
395 return () => {
396 window.cancelAnimationFrame(frameId);
397 element.removeEventListener("scroll", onScroll);
398 resizeObserver.disconnect();
399 };
400 }, [updateTurnStripScrollState]);
401​
402 useEffect(() => {
403 const frameId = window.requestAnimationFrame(() => updateTurnStripScrollState());
404 return () => {
405 window.cancelAnimationFrame(frameId);
406 };
407 }, [orderedTurnDiffSummaries, selectedTurnId, updateTurnStripScrollState]);
408​
409 useEffect(() => {
410 const element = turnStripRef.current;
411 if (!element) return;
412​
413 const selectedChip = element.querySelector<HTMLElement>("[data-turn-chip-selected='true']");
414 selectedChip?.scrollIntoView({ block: "nearest", inline: "nearest", behavior: "smooth" });
415 }, [selectedTurn?.turnId, selectedTurnId]);
416​
417 const headerRow = (
418 <>
419 <div className="relative min-w-0 flex-1 [-webkit-app-region:no-drag]">
420 {canScrollTurnStripLeft && (
421 <div className="pointer-events-none absolute inset-y-0 left-8 z-10 w-7 bg-linear-to-r from-card to-transparent" />
422 )}
423 {canScrollTurnStripRight && (
424 <div className="pointer-events-none absolute inset-y-0 right-8 z-10 w-7 bg-linear-to-l from-card to-transparent" />
425 )}
426 <button
427 type="button"
428 className={cn(
429 "absolute left-0 top-1/2 z-20 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded-md border bg-background/90 text-muted-foreground transition-colors",
430 canScrollTurnStripLeft
431 ? "border-border/70 hover:border-border hover:text-foreground"
432 : "cursor-not-allowed border-border/40 text-muted-foreground/40",
433 )}
434 onClick={() => scrollTurnStripBy(-180)}
435 disabled={!canScrollTurnStripLeft}
436 aria-label="Scroll turn list left"
437 >
438 <ChevronLeftIcon className="size-3.5" />
439 </button>
440 <button
441 type="button"
442 className={cn(
443 "absolute right-0 top-1/2 z-20 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded-md border bg-background/90 text-muted-foreground transition-colors",
444 canScrollTurnStripRight
445 ? "border-border/70 hover:border-border hover:text-foreground"
446 : "cursor-not-allowed border-border/40 text-muted-foreground/40",
447 )}
448 onClick={() => scrollTurnStripBy(180)}
449 disabled={!canScrollTurnStripRight}
450 aria-label="Scroll turn list right"
451 >
452 <ChevronRightIcon className="size-3.5" />
453 </button>
454 <div
455 ref={turnStripRef}
456 className="turn-chip-strip flex gap-1 overflow-x-auto px-8 py-0.5"
457 onWheel={onTurnStripWheel}
458 >
459 <button
460 type="button"
461 className="shrink-0 rounded-md"
462 onClick={selectWholeConversation}
463 data-turn-chip-selected={selectedTurnId === null}
464 >
465 <div
466 className={cn(
467 "rounded-md border px-2 py-1 text-left transition-colors",
468 selectedTurnId === null
469 ? "border-border bg-accent text-accent-foreground"
470 : "border-border/70 bg-background/70 text-muted-foreground/80 hover:border-border hover:text-foreground/80",
471 )}
472 >
473 <div className="text-[10px] leading-tight font-medium">All turns</div>
474 </div>
475 </button>
476 {orderedTurnDiffSummaries.map((summary) => (
477 <button
478 key={summary.turnId}
479 type="button"
480 className="shrink-0 rounded-md"
481 onClick={() => selectTurn(summary.turnId)}
482 title={summary.turnId}
483 data-turn-chip-selected={summary.turnId === selectedTurn?.turnId}
484 >
485 <div
486 className={cn(
487 "rounded-md border px-2 py-1 text-left transition-colors",
488 summary.turnId === selectedTurn?.turnId
489 ? "border-border bg-accent text-accent-foreground"
490 : "border-border/70 bg-background/70 text-muted-foreground/80 hover:border-border hover:text-foreground/80",
491 )}
492 >
493 <div className="flex items-center gap-1">
494 <span className="text-[10px] leading-tight font-medium">
495 Turn{" "}
496 {summary.checkpointTurnCount ??
497 inferredCheckpointTurnCountByTurnId[summary.turnId] ??
498 "?"}
499 </span>
500 <span className="text-[9px] leading-tight opacity-70">
501 {formatShortTimestamp(summary.completedAt, settings.timestampFormat)}
502 </span>
503 </div>
504 </div>
505 </button>
506 ))}
507 </div>
508 </div>
509 <div className="flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]">
510 <ToggleGroup
511 className="shrink-0"
512 variant="outline"
513 size="xs"
514 value={[diffRenderMode]}
515 onValueChange={(value) => {
516 const next = value[0];
517 if (next === "stacked" || next === "split") {
518 setDiffRenderMode(next);
519 }
520 }}
521 >
522 <Toggle aria-label="Stacked diff view" value="stacked">
523 <Rows3Icon className="size-3" />
524 </Toggle>
525 <Toggle aria-label="Split diff view" value="split">
526 <Columns2Icon className="size-3" />
527 </Toggle>
528 </ToggleGroup>
529 <Toggle
530 aria-label={diffWordWrap ? "Disable diff line wrapping" : "Enable diff line wrapping"}
531 title={diffWordWrap ? "Disable line wrapping" : "Enable line wrapping"}
532 variant="outline"
533 size="xs"
534 pressed={diffWordWrap}
535 onPressedChange={(pressed) => {
536 setDiffWordWrap(Boolean(pressed));
537 }}
538 >
539 <TextWrapIcon className="size-3" />
540 </Toggle>
541 </div>
542 </>
543 );
544​
545 return (
546 <DiffPanelShell mode={mode} header={headerRow}>
547 {!activeThread ? (
548 <div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
549 Select a thread to inspect turn diffs.
550 </div>
551 ) : !isGitRepo ? (
552 <div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
553 Turn diffs are unavailable because this project is not a git repository.
554 </div>
555 ) : orderedTurnDiffSummaries.length === 0 ? (
556 <div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
557 No completed turns yet.
558 </div>
559 ) : (
560 <>
561 <div
562 ref={patchViewportRef}
563 className="diff-panel-viewport min-h-0 min-w-0 flex-1 overflow-hidden"
564 >
565 {checkpointDiffError && !renderablePatch && (
566 <div className="px-3">
567 <p className="mb-2 text-[11px] text-red-500/80">{checkpointDiffError}</p>
568 </div>
569 )}
570 {!renderablePatch ? (
571 isLoadingCheckpointDiff ? (
572 <DiffPanelLoadingState label="Loading checkpoint diff..." />
573 ) : (
574 <div className="flex h-full items-center justify-center px-3 py-2 text-xs text-muted-foreground/70">
575 <p>
576 {hasNoNetChanges
577 ? "No net changes in this selection."
578 : "No patch available for this selection."}
579 </p>
580 </div>
581 )
582 ) : renderablePatch.kind === "files" ? (
583 <Virtualizer
584 className="diff-render-surface h-full min-h-0 overflow-auto px-2 pb-2"
585 config={{
586 overscrollSize: 600,
587 intersectionObserverMargin: 1200,
588 }}
589 >
590 {renderableFiles.map((fileDiff) => {
591 const filePath = resolveFileDiffPath(fileDiff);
592 const fileKey = buildFileDiffRenderKey(fileDiff);
593 const themedFileKey = `${fileKey}:${resolvedTheme}`;
594 return (
595 <div
596 key={themedFileKey}
597 data-diff-file-path={filePath}
598 className="diff-render-file mb-2 rounded-md first:mt-2 last:mb-0"
599 onClickCapture={(event) => {
600 const nativeEvent = event.nativeEvent as MouseEvent;
601 const composedPath = nativeEvent.composedPath?.() ?? [];
602 const clickedHeader = composedPath.some((node) => {
603 if (!(node instanceof Element)) return false;
604 return node.hasAttribute("data-title");
605 });
606 if (!clickedHeader) return;
607 openDiffFileInEditor(filePath);
608 }}
609 >
610 <FileDiff
611 fileDiff={fileDiff}
612 options={{
613 diffStyle: diffRenderMode === "split" ? "split" : "unified",
614 lineDiffType: "none",
615 overflow: diffWordWrap ? "wrap" : "scroll",
616 theme: resolveDiffThemeName(resolvedTheme),
617 themeType: resolvedTheme as DiffThemeType,
618 unsafeCSS: DIFF_PANEL_UNSAFE_CSS,
619 }}
620 />
621 </div>
622 );
623 })}
624 </Virtualizer>
625 ) : (
626 <div className="h-full overflow-auto p-2">
627 <div className="space-y-2">
628 <p className="text-[11px] text-muted-foreground/75">{renderablePatch.reason}</p>
629 <pre
630 className={cn(
631 "max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90",
632 diffWordWrap
633 ? "overflow-auto whitespace-pre-wrap wrap-break-word"
634 : "overflow-auto",
635 )}
636 >
637 {renderablePatch.text}
638 </pre>
639 </div>
640 </div>
641 )}
642 </div>
643 </>
644 )}
645 </DiffPanelShell>
646 );