The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 11:00 UTC
fix(web): copied code blocks drop the fence's trailing newline (#37284)
Julius Marminge committed
Nov 15, 2026 at 08:44 UTC
598296e8504d03f915cfac28fb8b6241289ae3b9
2 files changed
+23
-2
apps/web/src/components/chat/MarkdownCodeBlock.browser.test.tsx
+22
-1
@@ -1,4 +1,4 @@
1
-import { expect, it } from "vite-plus/test";
1
+import { expect, it, vi } from "vite-plus/test";
2
3
import { act, render } from "../../../test/render";
4
import "../../index.css";
@@ -33,3 +33,24 @@ it("follows a changed word wrap default while mounted", async () => {
33
await expect.element(screen.getByRole("button", { name: "Disable line wrap" })).toBeVisible();
34
expect(block()?.getAttribute("data-wrap")).toBe("true");
35
});
36
+
37
+it("copies a fenced command without the fence's closing newline", async () => {
38
+ await ensureClientSettingsHydrated();
39
+ await using screen = await render(
40
+ <MarkdownCodeBlock
41
+ code={"sudo pacman -S patchelf\n"}
42
+ language="bash"
43
+ fenceTitle={null}
44
+ theme="light"
45
+ isStreaming={false}
46
+ >
47
+ <pre>
48
+ <code>sudo pacman -S patchelf</code>
49
+ </pre>
50
+ </MarkdownCodeBlock>,
51
+ { router: false }, // The code block reads no route state.
52
+ );
53
+ using write = vi.spyOn(navigator.clipboard, "writeText").mockResolvedValue(undefined);
54
+ await screen.getByRole("button", { name: "Copy code" }).click();
55
+ await vi.waitFor(() => expect(write).toHaveBeenCalledWith("sudo pacman -S patchelf"));
56
+});
apps/web/src/components/chat/MarkdownCodeBlock.tsx
+1
-1
@@ -178,7 +178,7 @@ export function MarkdownCodeBlock({
178
// make the rendered command differ from what the terminal would receive.
179
!/[\p{Cc}\p{Cf}]/u.test(code.slice(0, -1));
180
181
- const handleCopy = () => copyToClipboard(code);
181
+ const handleCopy = () => copyToClipboard(code.endsWith("\n") ? code.slice(0, -1) : code);
182
183
const copyButton = (
184
<Tooltip>