Elffuss BraidHub

kikocis/continue public

Merge pull request #7560 from continuedev/dallin/hide-unchanged-diff

fix: don't show unchanged diff sections in extension UI
Changeset80ec3503f561d301369fb4a806f6d32727ecf0d10da73593dc175f1f00dcf800
AuthorDallin Romney <dallinromney@gmail.com> · 2025-09-04 22:08 -07:00
CommitterGitHub <noreply@github.com> · 2025-09-04 22:08 -07:00
Parentse42bdc2c5fca, 7bb9ac49a1e0

Browse the files at this changeset

1 file changed

modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.tsx +78 −53
@@ -14,6 +14,7 @@
1414 selectToolCallById,
1515 } from "../../../redux/selectors/selectToolCalls";
1616 import { performFindAndReplace } from "../../../util/clientTools/findAndReplaceUtils";
17+import { cn } from "../../../util/cn";
1718 import { getStatusIcon } from "./utils";
1819
1920 interface FindAndReplaceDisplayProps {
@@ -25,6 +26,48 @@
2526 historyIndex: number;
2627 }
2728
29+const MAX_SAME_LINES = 2;
30+
31+function EllipsisLine() {
32+ return (
33+ <div className="text-description-muted px-3 py-1 text-center font-mono">
34+ ⋯
35+ </div>
36+ );
37+}
38+
39+function DiffLines({
40+ lines,
41+ className = "",
42+ diffChar = " ",
43+ diffCharClass = "text-description-muted",
44+}: {
45+ lines: string[];
46+ diffChar?: string;
47+ diffCharClass?: string;
48+ className?: string;
49+}) {
50+ return (
51+ <>
52+ {lines.map((line, lineIndex) => {
53+ const isLastPartLine = lineIndex === lines.length - 1;
54+ if (line === "" && isLastPartLine) return null;
55+ return (
56+ <div
57+ key={lineIndex}
58+ className={cn("text-foreground px-3 py-px font-mono", className)}
59+ >
60+ <span className={cn("mr-2 select-none", diffCharClass)}>
61+ {diffChar}
62+ </span>
63+ {line}
64+ </div>
65+ );
66+ })}
67+ </>
68+ );
69+}
70+
2871 export function FindAndReplaceDisplay({
2972 fileUri,
3073 relativeFilePath,
@@ -200,70 +243,52 @@
200243 <pre
201244 className={`bg-editor m-0 w-full text-xs leading-tight ${config?.ui?.codeWrap ? "whitespace-pre-wrap" : "whitespace-pre"}`}
202245 >
203- {diffResult.diff.map((part, index) => {
246+ {diffResult.diff?.map((part, index) => {
204247 if (part.removed) {
205248 return (
206- <div
249+ <DiffLines
207250 key={index}
208- className="text-foreground border-l-4 border-red-900 bg-red-900/30"
209- >
210- {part.value.split("\n").map((line, lineIndex) => {
211- if (
212- line === "" &&
213- lineIndex === part.value.split("\n").length - 1
214- )
215- return null;
216- return (
217- <div key={lineIndex} className="px-3 py-px font-mono">
218- <span className="mr-2 select-none text-red-600">-</span>
219- {line}
220- </div>
221- );
222- })}
223- </div>
251+ lines={part.value.split("\n")}
252+ className="border-l-4 border-red-900 bg-red-900/30"
253+ diffCharClass="text-red-600"
254+ diffChar="-"
255+ />
224256 );
225257 } else if (part.added) {
226258 return (
227- <div
259+ <DiffLines
228260 key={index}
229- className="text-foreground border-l-4 border-green-600 bg-green-600/20"
230- >
231- {part.value.split("\n").map((line, lineIndex) => {
232- if (
233- line === "" &&
234- lineIndex === part.value.split("\n").length - 1
235- )
236- return null;
237- return (
238- <div key={lineIndex} className="px-3 py-px font-mono">
239- <span className="mr-2 select-none text-green-600">+</span>
240- {line}
241- </div>
242- );
243- })}
244- </div>
261+ lines={part.value.split("\n")}
262+ diffCharClass="text-green-600"
263+ className="border-l-4 border-green-600 bg-green-600/20"
264+ diffChar="+"
265+ />
245266 );
246267 } else {
268+ const isFirst = index === 0;
269+ const isLast = index === diffResult.diff.length - 1;
270+ const lines = part.value.split("\n");
271+ const showStartEllipsis = isFirst && lines.length > MAX_SAME_LINES;
272+ const showEndEllipsis = isLast && lines.length > MAX_SAME_LINES;
273+ const showMiddleEllipses =
274+ !isFirst && !isLast && lines.length > MAX_SAME_LINES * 2 + 1;
275+
276+ const startLines = showStartEllipsis
277+ ? lines.slice(-MAX_SAME_LINES)
278+ : showMiddleEllipses || showEndEllipsis
279+ ? lines.slice(0, MAX_SAME_LINES)
280+ : lines;
281+ const endLines = showMiddleEllipses
282+ ? lines.slice(-MAX_SAME_LINES)
283+ : [];
284+
247285 return (
248286 <div key={index}>
249- {part.value.split("\n").map((line, lineIndex) => {
250- if (
251- line === "" &&
252- lineIndex === part.value.split("\n").length - 1
253- )
254- return null;
255- return (
256- <div
257- key={lineIndex}
258- className="text-foreground px-3 py-px font-mono"
259- >
260- <span className="text-description-muted mr-2 select-none">
261- {" "}
262- </span>
263- {line}
264- </div>
265- );
266- })}
287+ {showStartEllipsis && <EllipsisLine />}
288+ <DiffLines lines={startLines} />
289+ {showMiddleEllipses && <EllipsisLine />}
290+ <DiffLines lines={endLines} />
291+ {showEndEllipsis && <EllipsisLine />}
267292 </div>
268293 );
269294 }