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:
Bonerush 2026-05-26 15:42:09 +08:00
parent c982104476
commit 56828e15b8
3 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -153,6 +153,9 @@ export function getPatchForDisplay({
convertLeadingTabsToSpaces(new_string),
)
if (escapedOldString === '') {
return escapedNewString
}
if (replace_all) {
return p.replaceAll(escapedOldString, () => escapedNewString)
} else {