Changesets · Branches · Tags · Compare
| Changeset | c44e8ca3a7d496a5a8a98ae41549878fbc7369f1c54b0a7796ac41c98b2173c2 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-17 15:22 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-09-17 15:22 -07:00 |
| Parents | 5c43853c2101, c33d3f5d8d05 |
4 files changed
modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.test.tsx +10 −3
| @@ -19,9 +19,16 @@ | ||
| 19 | 19 | useFontSize: () => 14, |
| 20 | 20 | })); |
| 21 | 21 | |
| 22 | -vi.mock("../../../util/clientTools/findAndReplaceUtils", () => ({ | |
| 23 | - performFindAndReplace: vi.fn(), | |
| 24 | -})); | |
| 22 | +vi.mock("../../../util/clientTools/findAndReplaceUtils", async () => { | |
| 23 | + const actual = await vi.importActual( | |
| 24 | + "../../../util/clientTools/findAndReplaceUtils", | |
| 25 | + ); | |
| 26 | + | |
| 27 | + return { | |
| 28 | + performFindAndReplace: vi.fn(), | |
| 29 | + trimEmptyLines: actual.trimEmptyLines, | |
| 30 | + }; | |
| 31 | +}); | |
| 25 | 32 | |
| 26 | 33 | vi.mock("./utils", () => ({ |
| 27 | 34 | getStatusIcon: vi.fn(() => <div data-testid="status-icon">✓</div>), |
modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.tsx +8 −3
| @@ -13,7 +13,10 @@ | ||
| 13 | 13 | selectApplyStateByToolCallId, |
| 14 | 14 | selectToolCallById, |
| 15 | 15 | } from "../../../redux/selectors/selectToolCalls"; |
| 16 | -import { performFindAndReplace } from "../../../util/clientTools/findAndReplaceUtils"; | |
| 16 | +import { | |
| 17 | + performFindAndReplace, | |
| 18 | + trimEmptyLines, | |
| 19 | +} from "../../../util/clientTools/findAndReplaceUtils"; | |
| 17 | 20 | import { cn } from "../../../util/cn"; |
| 18 | 21 | import { getStatusIcon } from "./utils"; |
| 19 | 22 | |
| @@ -313,14 +316,16 @@ | ||
| 313 | 316 | const showMiddleEllipses = |
| 314 | 317 | !isFirst && !isLast && lines.length > MAX_SAME_LINES * 2 + 1; |
| 315 | 318 | |
| 316 | - const startLines = showStartEllipsis | |
| 319 | + let startLines = showStartEllipsis | |
| 317 | 320 | ? lines.slice(-MAX_SAME_LINES) |
| 318 | 321 | : showMiddleEllipses || showEndEllipsis |
| 319 | 322 | ? lines.slice(0, MAX_SAME_LINES) |
| 320 | 323 | : lines; |
| 321 | - const endLines = showMiddleEllipses | |
| 324 | + startLines = trimEmptyLines({ lines: startLines, fromEnd: false }); | |
| 325 | + let endLines = showMiddleEllipses | |
| 322 | 326 | ? lines.slice(-MAX_SAME_LINES) |
| 323 | 327 | : []; |
| 328 | + endLines = trimEmptyLines({ lines: endLines, fromEnd: true }); | |
| 324 | 329 | |
| 325 | 330 | return ( |
| 326 | 331 | <div key={index}> |
modified gui/src/util/clientTools/findAndReplaceUtils.test.ts +21 −0
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | EMPTY_NON_FIRST_EDIT_MESSAGE, |
| 5 | 5 | FOUND_MULTIPLE_FIND_STRINGS_ERROR, |
| 6 | 6 | performFindAndReplace, |
| 7 | + trimEmptyLines, | |
| 7 | 8 | validateCreatingForMultiEdit, |
| 8 | 9 | validateSingleEdit, |
| 9 | 10 | } from "./findAndReplaceUtils"; |
| @@ -454,3 +455,23 @@ | ||
| 454 | 455 | }); |
| 455 | 456 | }); |
| 456 | 457 | }); |
| 458 | + | |
| 459 | +describe("trimEmptyLines", () => { | |
| 460 | + it("trims leading empty lines from start", () => { | |
| 461 | + const input = ["", "", "a", "", "b"]; | |
| 462 | + const result = trimEmptyLines({ lines: input, fromEnd: false }); | |
| 463 | + expect(result).toEqual(["a", "", "b"]); | |
| 464 | + }); | |
| 465 | + | |
| 466 | + it("trims trailing empty lines from end", () => { | |
| 467 | + const input = ["a", "", "b", "", ""]; | |
| 468 | + const result = trimEmptyLines({ lines: input, fromEnd: true }); | |
| 469 | + expect(result).toEqual(["a", "", "b"]); | |
| 470 | + }); | |
| 471 | + | |
| 472 | + it("returns empty array when all lines are empty", () => { | |
| 473 | + const input = ["", "", ""]; | |
| 474 | + const result = trimEmptyLines({ lines: input, fromEnd: false }); | |
| 475 | + expect(result).toEqual([]); | |
| 476 | + }); | |
| 477 | +}); |
modified gui/src/util/clientTools/findAndReplaceUtils.ts +19 −0
| @@ -95,3 +95,22 @@ | ||
| 95 | 95 | |
| 96 | 96 | return isCreating; |
| 97 | 97 | } |
| 98 | + | |
| 99 | +export function trimEmptyLines({ | |
| 100 | + lines, | |
| 101 | + fromEnd, | |
| 102 | +}: { | |
| 103 | + lines: string[]; | |
| 104 | + fromEnd: boolean; | |
| 105 | +}): string[] { | |
| 106 | + lines = fromEnd ? lines.toReversed() : lines.slice(); | |
| 107 | + const newLines: string[] = []; | |
| 108 | + let shouldContinueRemoving = true; | |
| 109 | + for (let index = 0; index < lines.length; index++) { | |
| 110 | + const line = lines[index]; | |
| 111 | + if (shouldContinueRemoving && line.trim() === "") continue; | |
| 112 | + shouldContinueRemoving = false; | |
| 113 | + newLines.push(line); | |
| 114 | + } | |
| 115 | + return fromEnd ? newLines.reverse() : newLines; | |
| 116 | +} |