Skip to content

Commit bfa1911

Browse files
fix(chat): address fourth round of PR review feedback
- Fix ReadOnlyToolCall lineRange: disk read always returns the whole file so always display 1–N (trimming trailing newline before counting) - Fix Shiki fallback to render escaped plain text instead of empty strings when codeToHtml fails for the "text" language itself - Trim trailing newline before computing lineCount in ShowCode so files ending with \n do not trigger isOverflowing one line early
1 parent 387ef68 commit bfa1911

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

apps/desktop/src/renderer/components/Chat/ChatInterface/components/ReadOnlyToolCall/ReadOnlyToolCall.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,9 @@ export function ReadOnlyToolCall({
9090

9191
const lineRange = hasFileContent
9292
? (() => {
93-
const startLine =
94-
Number(
95-
args.startLine ?? args.start_line ?? args.offset ?? args.from ?? 1,
96-
) || 1;
97-
const lineCount = fileContent.split("\n").length;
98-
const endLine = startLine + lineCount - 1;
99-
return startLine === 1 && endLine === lineCount
100-
? `1–${lineCount}`
101-
: `${startLine}${endLine}`;
93+
// The disk read always returns the whole file, so report 1–N
94+
const lineCount = fileContent.trimEnd().split("\n").length;
95+
return `1–${lineCount}`;
10296
})()
10397
: null;
10498

packages/ui/src/components/ai-elements/code-block.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ export async function highlightCode(
8080
]);
8181
} catch {
8282
if (language === ("text" as BundledLanguage)) {
83-
return ["", ""];
83+
const escaped = code
84+
.replace(/&/g, "&")
85+
.replace(/</g, "&lt;")
86+
.replace(/>/g, "&gt;");
87+
const html = `<pre><code>${escaped}</code></pre>`;
88+
return [html, html];
8489
}
8590
// Unknown/unsupported language — fall back to plain text
8691
return highlightCode(

packages/ui/src/components/ai-elements/show-code.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function ShowCode({
8080
const [isCopied, setIsCopied] = useState(false);
8181
const [isExpanded, setIsExpanded] = useState(false);
8282

83-
const lineCount = code.split("\n").length;
83+
const lineCount = code.trimEnd().split("\n").length;
8484
const isOverflowing = lineCount > maxLines;
8585

8686
const handleCopy = async () => {

0 commit comments

Comments
 (0)