fix: diff display edge cases for empty patches and hunks
- FileEditToolDiff: show "No changes to display" when patch is empty - FileWriteToolDiff: guard against empty hunks array - getPatchForDisplay: skip replace when old_string is empty
This commit is contained in:
parent
c982104476
commit
56828e15b8
|
|
@ -37,6 +37,15 @@ export function FileEditToolDiff(props: Props): React.ReactNode {
|
|||
function DiffBody({ promise, file_path }: { promise: Promise<DiffData>; file_path: string }): React.ReactNode {
|
||||
const { patch, firstLine, fileContent } = use(promise);
|
||||
const { columns } = useTerminalSize();
|
||||
|
||||
if (patch.length === 0) {
|
||||
return (
|
||||
<DiffFrame>
|
||||
<Text dimColor>No changes to display</Text>
|
||||
</DiffFrame>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<DiffFrame>
|
||||
<StructuredDiffList
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ export function FileWriteToolDiff({ file_path, content, fileExists, oldContent }
|
|||
borderRight={false}
|
||||
paddingX={paddingX}
|
||||
>
|
||||
{hunks ? (
|
||||
{hunks && hunks.length > 0 ? (
|
||||
intersperse(
|
||||
hunks.map(_ => (
|
||||
<StructuredDiff
|
||||
|
|
|
|||
|
|
@ -153,6 +153,9 @@ export function getPatchForDisplay({
|
|||
convertLeadingTabsToSpaces(new_string),
|
||||
)
|
||||
|
||||
if (escapedOldString === '') {
|
||||
return escapedNewString
|
||||
}
|
||||
if (replace_all) {
|
||||
return p.replaceAll(escapedOldString, () => escapedNewString)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user