Changesets · Branches · Tags · Compare
| Changeset | 80ec3503f561d301369fb4a806f6d32727ecf0d10da73593dc175f1f00dcf800 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-04 22:08 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-09-04 22:08 -07:00 |
| Parents | e42bdc2c5fca, 7bb9ac49a1e0 |
1 file changed
modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.tsx +78 −53
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | selectToolCallById, |
| 15 | 15 | } from "../../../redux/selectors/selectToolCalls"; |
| 16 | 16 | import { performFindAndReplace } from "../../../util/clientTools/findAndReplaceUtils"; |
| 17 | +import { cn } from "../../../util/cn"; | |
| 17 | 18 | import { getStatusIcon } from "./utils"; |
| 18 | 19 | |
| 19 | 20 | interface FindAndReplaceDisplayProps { |
| @@ -25,6 +26,48 @@ | ||
| 25 | 26 | historyIndex: number; |
| 26 | 27 | } |
| 27 | 28 | |
| 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 | + | |
| 28 | 71 | export function FindAndReplaceDisplay({ |
| 29 | 72 | fileUri, |
| 30 | 73 | relativeFilePath, |
| @@ -200,70 +243,52 @@ | ||
| 200 | 243 | <pre |
| 201 | 244 | className={`bg-editor m-0 w-full text-xs leading-tight ${config?.ui?.codeWrap ? "whitespace-pre-wrap" : "whitespace-pre"}`} |
| 202 | 245 | > |
| 203 | - {diffResult.diff.map((part, index) => { | |
| 246 | + {diffResult.diff?.map((part, index) => { | |
| 204 | 247 | if (part.removed) { |
| 205 | 248 | return ( |
| 206 | - <div | |
| 249 | + <DiffLines | |
| 207 | 250 | 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 | + /> | |
| 224 | 256 | ); |
| 225 | 257 | } else if (part.added) { |
| 226 | 258 | return ( |
| 227 | - <div | |
| 259 | + <DiffLines | |
| 228 | 260 | 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 | + /> | |
| 245 | 266 | ); |
| 246 | 267 | } 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 | + | |
| 247 | 285 | return ( |
| 248 | 286 | <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 />} | |
| 267 | 292 | </div> |
| 268 | 293 | ); |
| 269 | 294 | } |