Elffuss BraidHub

kikocis/continue public

refactor function definition
Changeset7bbe94906926df2fa96e6ddea914f281c2f0c0cd857884ea29f2432bf6e78822
Authoruinstinct <61635505+uinstinct@users.noreply.github.com> · 2025-09-17 15:23 +05:30
Committeruinstinct <61635505+uinstinct@users.noreply.github.com> · 2025-09-17 15:23 +05:30
Parentsc38cacf093af

Browse the files at this changeset

3 files changed

modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.test.tsx +1 −1
@@ -26,7 +26,7 @@
2626
2727 return {
2828 performFindAndReplace: vi.fn(),
29- removeEmptyLines: actual.removeEmptyLines,
29+ trimEmptyLines: actual.trimEmptyLines,
3030 };
3131 });
3232
modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.tsx +3 −3
@@ -15,7 +15,7 @@
1515 } from "../../../redux/selectors/selectToolCalls";
1616 import {
1717 performFindAndReplace,
18- removeEmptyLines,
18+ trimEmptyLines,
1919 } from "../../../util/clientTools/findAndReplaceUtils";
2020 import { cn } from "../../../util/cn";
2121 import { getStatusIcon } from "./utils";
@@ -321,11 +321,11 @@
321321 : showMiddleEllipses || showEndEllipsis
322322 ? lines.slice(0, MAX_SAME_LINES)
323323 : lines;
324- startLines = removeEmptyLines.fromStart(startLines);
324+ startLines = trimEmptyLines({ lines: startLines, fromEnd: false });
325325 let endLines = showMiddleEllipses
326326 ? lines.slice(-MAX_SAME_LINES)
327327 : [];
328- endLines = removeEmptyLines.fromEnd(endLines);
328+ endLines = trimEmptyLines({ lines: endLines, fromEnd: true });
329329
330330 return (
331331 <div key={index}>
modified gui/src/util/clientTools/findAndReplaceUtils.ts +18 −21
@@ -96,24 +96,21 @@
9696 return isCreating;
9797 }
9898
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+}