Elffuss BraidHub

kikocis/continue public

feat: show diff stats in find and replace toolbar
Changesetd690ac0b3d66a0b0df409f483fd0c4db0aa64d4b0fc70239190235144d7747b3
AuthorNate <sestinj@gmail.com> · 2025-09-10 19:50 -07:00
CommitterNate <sestinj@gmail.com> · 2025-09-10 19:50 -07:00
Parents35b484ef8f94

Browse the files at this changeset

1 file changed

modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.tsx +59 −21
@@ -68,6 +68,19 @@
6868 );
6969 }
7070
71+function DiffStats({ added, removed }: { added: number; removed: number }) {
72+ if (added === 0 && removed === 0) {
73+ return null;
74+ }
75+
76+ return (
77+ <div className="flex items-center gap-1 font-mono text-xs">
78+ {added > 0 && <span className="text-success">+{added}</span>}
79+ {removed > 0 && <span className="text-error">-{removed}</span>}
80+ </div>
81+ );
82+}
83+
7184 export function FindAndReplaceDisplay({
7285 fileUri,
7386 relativeFilePath,
@@ -141,6 +154,30 @@
141154 }
142155 }, [currentFileContent, edits]);
143156
157+ const diffStats = useMemo(() => {
158+ if (!diffResult?.diff) {
159+ return { added: 0, removed: 0 };
160+ }
161+
162+ let added = 0;
163+ let removed = 0;
164+
165+ diffResult.diff.forEach((part) => {
166+ const lines = part.value.split("\n");
167+ // Exclude empty line at the end (similar to DiffLines component logic)
168+ const lineCount =
169+ lines[lines.length - 1] === "" ? lines.length - 1 : lines.length;
170+
171+ if (part.added) {
172+ added += lineCount;
173+ } else if (part.removed) {
174+ removed += lineCount;
175+ }
176+ });
177+
178+ return { added, removed };
179+ }, [diffResult?.diff]);
180+
144181 const statusIcon = useMemo(() => {
145182 const status = toolCallState?.status;
146183 if (status) {
@@ -174,24 +211,27 @@
174211 setIsExpanded(!showContent);
175212 }}
176213 >
177- <div className="flex max-w-[50%] flex-row items-center text-xs">
178- {statusIcon}
179- <ChevronDownIcon
180- data-testid="toggle-find-and-replace-diff"
181- className={`text-lightgray h-3.5 w-3.5 flex-shrink-0 cursor-pointer select-none transition-all hover:brightness-125 ${
182- showContent ? "rotate-0" : "-rotate-90"
183- }`}
184- />
185- <FileInfo
186- filepath={displayName || "..."}
187- onClick={(e) => {
188- if (!fileUri) {
189- return;
190- }
191- e.stopPropagation();
192- ideMessenger.post("openFile", { path: fileUri });
193- }}
194- />
214+ <div className="flex min-w-0 flex-1 flex-row items-center gap-2 text-xs">
215+ <div className="flex min-w-0 flex-row items-center">
216+ {statusIcon}
217+ <ChevronDownIcon
218+ data-testid="toggle-find-and-replace-diff"
219+ className={`text-lightgray h-3.5 w-3.5 flex-shrink-0 cursor-pointer select-none transition-all hover:brightness-125 ${
220+ showContent ? "rotate-0" : "-rotate-90"
221+ }`}
222+ />
223+ <FileInfo
224+ filepath={displayName || "..."}
225+ onClick={(e) => {
226+ if (!fileUri) {
227+ return;
228+ }
229+ e.stopPropagation();
230+ ideMessenger.post("openFile", { path: fileUri });
231+ }}
232+ />
233+ </div>
234+ <DiffStats added={diffStats.added} removed={diffStats.removed} />
195235 </div>
196236
197237 {applyState && (
@@ -237,9 +277,7 @@
237277 }
238278
239279 return renderContainer(
240- <div
241- className="thin-scrollbar max-h-72 overflow-auto"
242- >
280+ <div className="thin-scrollbar max-h-72 overflow-auto">
243281 <pre
244282 className={`bg-editor m-0 w-fit min-w-full text-xs leading-tight ${config?.ui?.codeWrap ? "whitespace-pre-wrap" : "whitespace-pre"}`}
245283 >