Changesets · Branches · Tags · Compare
| Changeset | d690ac0b3d66a0b0df409f483fd0c4db0aa64d4b0fc70239190235144d7747b3 |
|---|---|
| Author | Nate <sestinj@gmail.com> · 2025-09-10 19:50 -07:00 |
| Committer | Nate <sestinj@gmail.com> · 2025-09-10 19:50 -07:00 |
| Parents | 35b484ef8f94 |
1 file changed
modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.tsx +59 −21
| @@ -68,6 +68,19 @@ | ||
| 68 | 68 | ); |
| 69 | 69 | } |
| 70 | 70 | |
| 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 | + | |
| 71 | 84 | export function FindAndReplaceDisplay({ |
| 72 | 85 | fileUri, |
| 73 | 86 | relativeFilePath, |
| @@ -141,6 +154,30 @@ | ||
| 141 | 154 | } |
| 142 | 155 | }, [currentFileContent, edits]); |
| 143 | 156 | |
| 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 | + | |
| 144 | 181 | const statusIcon = useMemo(() => { |
| 145 | 182 | const status = toolCallState?.status; |
| 146 | 183 | if (status) { |
| @@ -174,24 +211,27 @@ | ||
| 174 | 211 | setIsExpanded(!showContent); |
| 175 | 212 | }} |
| 176 | 213 | > |
| 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} /> | |
| 195 | 235 | </div> |
| 196 | 236 | |
| 197 | 237 | {applyState && ( |
| @@ -237,9 +277,7 @@ | ||
| 237 | 277 | } |
| 238 | 278 | |
| 239 | 279 | return renderContainer( |
| 240 | - <div | |
| 241 | - className="thin-scrollbar max-h-72 overflow-auto" | |
| 242 | - > | |
| 280 | + <div className="thin-scrollbar max-h-72 overflow-auto"> | |
| 243 | 281 | <pre |
| 244 | 282 | className={`bg-editor m-0 w-fit min-w-full text-xs leading-tight ${config?.ui?.codeWrap ? "whitespace-pre-wrap" : "whitespace-pre"}`} |
| 245 | 283 | > |