Skip to content

Commit 2e2111b

Browse files
fix(web): split code span pastes that contain a backtick
A backtick pasted into a code span was inserted literally, but the single-backtick serializer cannot represent it, so the span rebuilt with the pasted text parsed as Markdown. Such pastes now take the Markdown path, like multiline pastes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b3c0b67 commit 2e2111b

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

‎apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -255,20 +255,25 @@ it.each([
255255
expect(serializeEditorDoc(editor.state.doc).value).toBe(expected);
256256
});
257257

258-
// regression: #25180 a multiline paste into a code span serialized as a span the parser cannot rebuild
259-
it("rebuilds a multiline paste into a code span unchanged", async () => {
260-
await using screen = await mountEditor("`xy`");
261-
const { editor } = screen;
262-
await act(async () => {
263-
editor.commands.setTextSelection(2);
264-
const clipboardData = new DataTransfer();
265-
clipboardData.setData("text/plain", " _a_\nb");
266-
editor.view.dom.dispatchEvent(new ClipboardEvent("paste", { clipboardData, cancelable: true }));
267-
});
268-
const { value } = serializeEditorDoc(editor.state.doc);
269-
await using rebuilt = await mountEditor(value);
270-
expect(serializeEditorDoc(rebuilt.editor.state.doc).value).toBe(value);
271-
});
258+
// regression: #25180 a multiline or backtick paste into a code span serialized as a span the parser cannot rebuild
259+
it.each([" _a_\nb", "`__z__`"])(
260+
"rebuilds a paste of %j into a code span unchanged",
261+
async (pasted) => {
262+
await using screen = await mountEditor("`xy`");
263+
const { editor } = screen;
264+
await act(async () => {
265+
editor.commands.setTextSelection(2);
266+
const clipboardData = new DataTransfer();
267+
clipboardData.setData("text/plain", pasted);
268+
editor.view.dom.dispatchEvent(
269+
new ClipboardEvent("paste", { clipboardData, cancelable: true }),
270+
);
271+
});
272+
const { value } = serializeEditorDoc(editor.state.doc);
273+
await using rebuilt = await mountEditor(value);
274+
expect(serializeEditorDoc(rebuilt.editor.state.doc).value).toBe(value);
275+
},
276+
);
272277

273278
it("keeps the caret inside unknown dollar text across rich and plain remounts", async () => {
274279
const value = "echo $HOME now";

‎apps/web/src/components/ComposerPromptEditorTiptap.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,9 +1373,9 @@ function ComposerPromptEditorTiptapInner(
13731373
event.preventDefault();
13741374
// Paste verbatim inside fences and code spans; markdown parsing would split blocks and create unsupported chips.
13751375
const { storedMarks, selection } = view.state;
1376-
// Code spans cannot hold a newline, so multiline pastes take the Markdown path and split the span.
1376+
// Code spans cannot hold a newline or backtick, so those pastes take the Markdown path and split the span.
13771377
const inCodeSpan =
1378-
!pastedText.includes("\n") &&
1378+
!/[\n`]/.test(pastedText) &&
13791379
(storedMarks ?? selection.$from.marks()).some((mark) => mark.type.name === "code");
13801380
if (isInCodeBlock(view) || inCodeSpan) {
13811381
const { from, to } = view.state.selection;

0 commit comments

Comments
 (0)