// A `Diff` content block, rendered as coloured hunks. ACP hands over whole // `oldText`/`newText`, so the lines and their `+added −removed` counts are // computed here (diff.ts) rather than parsed out of a patch. import { useMemo } from "react"; import { computeDiffLines, diffStats, type DiffLine } from "./diff.js"; import type { AcpDiff } from "../../types.js"; import { Copyable } from "./Copyable.js"; /** Column prefix by line kind. A `hunk` summary and an `eof` marker are their * own complete text, so neither takes one. */ const PREFIX: Record = { add: "+ ", del: "- ", ctx: " ", hunk: "", eof: "", }; export function diffLineText(line: DiffLine): string { return PREFIX[line.kind] + line.text; } export interface DiffViewProps { diff: AcpDiff; } export function DiffView({ diff }: DiffViewProps) { const lines = useMemo(() => computeDiffLines(diff.oldText, diff.newText), [diff.oldText, diff.newText]); const stats = useMemo(() => diffStats(lines), [lines]); const plain = useMemo(() => lines.map(diffLineText).join("\n"), [lines]); return (
{diff.path}
          {lines.map((line, index) => (
            
              {diffLineText(line)}
            
          ))}
        
); }