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 {
|
function DiffBody({ promise, file_path }: { promise: Promise<DiffData>; file_path: string }): React.ReactNode {
|
||||||
const { patch, firstLine, fileContent } = use(promise);
|
const { patch, firstLine, fileContent } = use(promise);
|
||||||
const { columns } = useTerminalSize();
|
const { columns } = useTerminalSize();
|
||||||
|
|
||||||
|
if (patch.length === 0) {
|
||||||
|
return (
|
||||||
|
<DiffFrame>
|
||||||
|
<Text dimColor>No changes to display</Text>
|
||||||
|
</DiffFrame>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DiffFrame>
|
<DiffFrame>
|
||||||
<StructuredDiffList
|
<StructuredDiffList
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ export function FileWriteToolDiff({ file_path, content, fileExists, oldContent }
|
||||||
borderRight={false}
|
borderRight={false}
|
||||||
paddingX={paddingX}
|
paddingX={paddingX}
|
||||||
>
|
>
|
||||||
{hunks ? (
|
{hunks && hunks.length > 0 ? (
|
||||||
intersperse(
|
intersperse(
|
||||||
hunks.map(_ => (
|
hunks.map(_ => (
|
||||||
<StructuredDiff
|
<StructuredDiff
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,9 @@ export function getPatchForDisplay({
|
||||||
convertLeadingTabsToSpaces(new_string),
|
convertLeadingTabsToSpaces(new_string),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (escapedOldString === '') {
|
||||||
|
return escapedNewString
|
||||||
|
}
|
||||||
if (replace_all) {
|
if (replace_all) {
|
||||||
return p.replaceAll(escapedOldString, () => escapedNewString)
|
return p.replaceAll(escapedOldString, () => escapedNewString)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user