Skip to content

Commit e4f1866

Browse files
committed
webview-ui: remove redundant CDATA replacements; improve unified diff header detection; reuse extractUnifiedDiff for new-file rendering
1 parent 43b76c9 commit e4f1866

File tree

2 files changed

+3
-24
lines changed

2 files changed

+3
-24
lines changed

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,6 @@ function computeDiffStats(diff?: string): { added: number; removed: number } | n
177177
return null
178178
}
179179

180-
/**
181-
* Converts new file content to unified diff format (all lines as additions)
182-
*/
183-
function convertNewFileToUnifiedDiff(content: string, filePath?: string): string {
184-
const fileName = filePath || "file"
185-
const lines = content.split("\n")
186-
187-
let diff = `--- /dev/null\n`
188-
diff += `+++ ${fileName}\n`
189-
diff += `@@ -0,0 +1,${lines.length} @@\n`
190-
191-
for (const line of lines) {
192-
diff += `+${line}\n`
193-
}
194-
195-
return diff
196-
}
197-
198180
export const ChatRowContent = ({
199181
message,
200182
lastModifiedMessage,
@@ -640,7 +622,7 @@ export const ChatRowContent = ({
640622
<div className="pl-6">
641623
<CodeAccordian
642624
path={tool.path}
643-
code={convertNewFileToUnifiedDiff(tool.content || "", tool.path)}
625+
code={cleanDiffContent ?? ""}
644626
language="diff"
645627
isLoading={message.partial}
646628
isExpanded={isExpanded}

webview-ui/src/utils/diffUtils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function extractUnifiedDiff(params: {
4040
/** Detects unified diff by presence of headers/hunks */
4141
function isUnifiedDiff(s: string): boolean {
4242
const hasHunk = /(^|\n)@@\s+-[0-9,]+\s+\+[0-9,]+\s+@@/.test(s)
43-
const hasHeaders = /(^|\n)---\s|\n\+\+\+\s/.test(s)
43+
const hasHeaders = /(^|\n)---\s|(^|\n)\+\+\+\s/.test(s)
4444
return hasHunk || hasHeaders
4545
}
4646

@@ -55,12 +55,9 @@ function isSearchReplace(s: string): boolean {
5555
function stripCData(s: string): string {
5656
return (
5757
s
58-
// Remove HTML-encoded and raw CDATA open
58+
// Remove HTML-encoded and raw CDATA open/close (case-insensitive covers both)
5959
.replace(/<!\[CDATA\[/gi, "")
60-
.replace(/<!\[CDATA\[/g, "")
61-
// Remove HTML-encoded and raw CDATA close
6260
.replace(/\]\]>/gi, "")
63-
.replace(/\]\]>/g, "")
6461
)
6562
}
6663

0 commit comments

Comments
 (0)