fix: remove empty lines from start/end in find and replace
This commit is contained in:
parent
f8ea904f3d
commit
a6adedb51a
2 changed files with 30 additions and 3 deletions
|
|
@ -13,7 +13,10 @@ import {
|
|||
selectApplyStateByToolCallId,
|
||||
selectToolCallById,
|
||||
} from "../../../redux/selectors/selectToolCalls";
|
||||
import { performFindAndReplace } from "../../../util/clientTools/findAndReplaceUtils";
|
||||
import {
|
||||
performFindAndReplace,
|
||||
removeEmptyLines,
|
||||
} from "../../../util/clientTools/findAndReplaceUtils";
|
||||
import { cn } from "../../../util/cn";
|
||||
import { getStatusIcon } from "./utils";
|
||||
|
||||
|
|
@ -313,14 +316,16 @@ export function FindAndReplaceDisplay({
|
|||
const showMiddleEllipses =
|
||||
!isFirst && !isLast && lines.length > MAX_SAME_LINES * 2 + 1;
|
||||
|
||||
const startLines = showStartEllipsis
|
||||
let startLines = showStartEllipsis
|
||||
? lines.slice(-MAX_SAME_LINES)
|
||||
: showMiddleEllipses || showEndEllipsis
|
||||
? lines.slice(0, MAX_SAME_LINES)
|
||||
: lines;
|
||||
const endLines = showMiddleEllipses
|
||||
startLines = removeEmptyLines.fromStart(startLines);
|
||||
let endLines = showMiddleEllipses
|
||||
? lines.slice(-MAX_SAME_LINES)
|
||||
: [];
|
||||
endLines = removeEmptyLines.fromEnd(endLines);
|
||||
|
||||
return (
|
||||
<div key={index}>
|
||||
|
|
|
|||
|
|
@ -95,3 +95,25 @@ 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(),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue