MCPcopy Create free account
hub / github.com/aghyad97/browserytools / TextDiffViewer

Function TextDiffViewer

src/components/TextDiffViewer.tsx:46–134  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44 const [left, setLeft] = useState<string>("");
45 const [right, setRight] = useState<string>("");
46
47 const diff = useMemo(() => diffLines(left, right), [left, right]);
48
49 const patchText = useMemo(
50 () =>
51 diff
52 .map((p) => {
53 const prefix = p.type === "add" ? "+" : p.type === "remove" ? "-" : " ";
54 return `${prefix}${p.text}`;
55 })
56 .join("\n"),
57 [diff],
58 );
59
60 return (
61 <ToolShell
62 slug="text-diff"
63 title={tc("tools.text-diff.name")}
64 sub={tc("tools.text-diff.description")}
65 >
66 <div className="space-y-4">
67 <TwoPane
68 start={
69 <Textarea
70 value={left}
71 onChange={(e) => setLeft(e.target.value)}
72 className="min-h-[260px] font-mono text-sm"
73 placeholder={t("originalPlaceholder")}
74 />
75 }
76 end={
77 <Textarea
78 value={right}
79 onChange={(e) => setRight(e.target.value)}
80 className="min-h-[260px] font-mono text-sm"
81 placeholder={t("modifiedPlaceholder")}
82 />
83 }
84 />
85
86 <OutputPanel
87 text={patchText}
88 copyLabel={t("copyPatch")}
89 copySuccessMessage={t("patchCopied")}
90 copyErrorMessage={t("copyFailed")}
91 >
92 <TwoPane
93 start={
94 <div className="p-3">
95 {left.split(/\r?\n/).map((line, i) => (
96 <div
97 key={i}
98 className="font-mono text-sm whitespace-pre-wrap break-words"
99 >
100 {line}
101 </div>
102 ))}
103 </div>

Callers

nothing calls this directly

Calls 2

diffLinesFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected