refactor function definition
This commit is contained in:
parent
02954f3f68
commit
9a4f4b43db
3 changed files with 22 additions and 25 deletions
|
|
@ -26,7 +26,7 @@ vi.mock("../../../util/clientTools/findAndReplaceUtils", async () => {
|
|||
|
||||
return {
|
||||
performFindAndReplace: vi.fn(),
|
||||
removeEmptyLines: actual.removeEmptyLines,
|
||||
trimEmptyLines: actual.trimEmptyLines,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import {
|
|||
} from "../../../redux/selectors/selectToolCalls";
|
||||
import {
|
||||
performFindAndReplace,
|
||||
removeEmptyLines,
|
||||
trimEmptyLines,
|
||||
} from "../../../util/clientTools/findAndReplaceUtils";
|
||||
import { cn } from "../../../util/cn";
|
||||
import { getStatusIcon } from "./utils";
|
||||
|
|
@ -321,11 +321,11 @@ export function FindAndReplaceDisplay({
|
|||
: showMiddleEllipses || showEndEllipsis
|
||||
? lines.slice(0, MAX_SAME_LINES)
|
||||
: lines;
|
||||
startLines = removeEmptyLines.fromStart(startLines);
|
||||
startLines = trimEmptyLines({ lines: startLines, fromEnd: false });
|
||||
let endLines = showMiddleEllipses
|
||||
? lines.slice(-MAX_SAME_LINES)
|
||||
: [];
|
||||
endLines = removeEmptyLines.fromEnd(endLines);
|
||||
endLines = trimEmptyLines({ lines: endLines, fromEnd: true });
|
||||
|
||||
return (
|
||||
<div key={index}>
|
||||
|
|
|
|||
|
|
@ -96,24 +96,21 @@ export function validateCreatingForMultiEdit(edits: EditOperation[]) {
|
|||
return isCreating;
|
||||
}
|
||||
|
||||
/**remove all empty lines from the start/end in an array of lines */
|
||||
export const removeEmptyLines = {
|
||||
_remove: (lines: string[]) => {
|
||||
const newLines = [];
|
||||
let index = 0,
|
||||
shouldContinueRemoving = true;
|
||||
while (index < lines.length) {
|
||||
if (shouldContinueRemoving && lines[index].trim() === "") {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
shouldContinueRemoving = false;
|
||||
newLines.push(lines[index]);
|
||||
index++;
|
||||
}
|
||||
return newLines;
|
||||
},
|
||||
fromStart: (lines: string[]) => removeEmptyLines._remove(lines),
|
||||
fromEnd: (lines: string[]) =>
|
||||
removeEmptyLines._remove(lines.toReversed()).toReversed(),
|
||||
};
|
||||
export function trimEmptyLines({
|
||||
lines,
|
||||
fromEnd,
|
||||
}: {
|
||||
lines: string[];
|
||||
fromEnd: boolean;
|
||||
}): string[] {
|
||||
lines = fromEnd ? lines.toReversed() : lines.slice();
|
||||
const newLines: string[] = [];
|
||||
let shouldContinueRemoving = true;
|
||||
for (let index = 0; index < lines.length; index++) {
|
||||
const line = lines[index];
|
||||
if (shouldContinueRemoving && line.trim() === "") continue;
|
||||
shouldContinueRemoving = false;
|
||||
newLines.push(line);
|
||||
}
|
||||
return fromEnd ? newLines.reverse() : newLines;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue