Changesets · Branches · Tags · Compare
| Changeset | 7bbe94906926df2fa96e6ddea914f281c2f0c0cd857884ea29f2432bf6e78822 |
|---|---|
| Author | uinstinct <61635505+uinstinct@users.noreply.github.com> · 2025-09-17 15:23 +05:30 |
| Committer | uinstinct <61635505+uinstinct@users.noreply.github.com> · 2025-09-17 15:23 +05:30 |
| Parents | c38cacf093af |
3 files changed
modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.test.tsx +1 −1
| @@ -26,7 +26,7 @@ | ||
| 26 | 26 | |
| 27 | 27 | return { |
| 28 | 28 | performFindAndReplace: vi.fn(), |
| 29 | - removeEmptyLines: actual.removeEmptyLines, | |
| 29 | + trimEmptyLines: actual.trimEmptyLines, | |
| 30 | 30 | }; |
| 31 | 31 | }); |
| 32 | 32 |
modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.tsx +3 −3
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | } from "../../../redux/selectors/selectToolCalls"; |
| 16 | 16 | import { |
| 17 | 17 | performFindAndReplace, |
| 18 | - removeEmptyLines, | |
| 18 | + trimEmptyLines, | |
| 19 | 19 | } from "../../../util/clientTools/findAndReplaceUtils"; |
| 20 | 20 | import { cn } from "../../../util/cn"; |
| 21 | 21 | import { getStatusIcon } from "./utils"; |
| @@ -321,11 +321,11 @@ | ||
| 321 | 321 | : showMiddleEllipses || showEndEllipsis |
| 322 | 322 | ? lines.slice(0, MAX_SAME_LINES) |
| 323 | 323 | : lines; |
| 324 | - startLines = removeEmptyLines.fromStart(startLines); | |
| 324 | + startLines = trimEmptyLines({ lines: startLines, fromEnd: false }); | |
| 325 | 325 | let endLines = showMiddleEllipses |
| 326 | 326 | ? lines.slice(-MAX_SAME_LINES) |
| 327 | 327 | : []; |
| 328 | - endLines = removeEmptyLines.fromEnd(endLines); | |
| 328 | + endLines = trimEmptyLines({ lines: endLines, fromEnd: true }); | |
| 329 | 329 | |
| 330 | 330 | return ( |
| 331 | 331 | <div key={index}> |
modified gui/src/util/clientTools/findAndReplaceUtils.ts +18 −21
| @@ -96,24 +96,21 @@ | ||
| 96 | 96 | return isCreating; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | -/**remove all empty lines from the start/end in an array of lines */ | |
| 100 | -export const removeEmptyLines = { | |
| 101 | - _remove: (lines: string[]) => { | |
| 102 | - const newLines = []; | |
| 103 | - let index = 0, | |
| 104 | - shouldContinueRemoving = true; | |
| 105 | - while (index < lines.length) { | |
| 106 | - if (shouldContinueRemoving && lines[index].trim() === "") { | |
| 107 | - index++; | |
| 108 | - continue; | |
| 109 | - } | |
| 110 | - shouldContinueRemoving = false; | |
| 111 | - newLines.push(lines[index]); | |
| 112 | - index++; | |
| 113 | - } | |
| 114 | - return newLines; | |
| 115 | - }, | |
| 116 | - fromStart: (lines: string[]) => removeEmptyLines._remove(lines), | |
| 117 | - fromEnd: (lines: string[]) => | |
| 118 | - removeEmptyLines._remove(lines.toReversed()).toReversed(), | |
| 119 | -}; | |
| 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 | +} |