The best way to control Claude Code, Codex and more from any computer or phone
fix(web): pasted CRLF text keeps its blank lines and caret in the composer (#27280)
Julius Marminge committed
Nov 11, 2026 at 16:51 UTC
4e6924753cac26b904b76f59a44cff026914a132
4 files changed
+34
-3
apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx
+20
@@ -362,6 +362,26 @@ it("keeps unknown dollar names editable when restoring and pasting a draft", asy
362
expect(serializeEditorDoc(editor.state.doc).value).toBe(value);
363
});
364
365
+it.each(["x\r\n\r\ny", "x\r\ry"])(
366
+ "pastes %j with the same blank line as x\\n\\ny",
367
+ async (text) => {
368
+ await using screen = await mountEditor("");
369
+ const { editor } = screen;
370
+ await act(async () => {
371
+ editor.commands.focus("end");
372
+ const clipboardData = new DataTransfer();
373
+ clipboardData.setData("text/plain", text);
374
+ editor.view.dom.dispatchEvent(
375
+ new ClipboardEvent("paste", { clipboardData, cancelable: true }),
376
+ );
377
+ });
378
+ const paragraphs: string[] = [];
379
+ editor.state.doc.forEach((node) => paragraphs.push(node.textContent));
380
+ expect(paragraphs).toEqual(["x", "", "y"]);
381
+ expect(serializeEditorDoc(editor.state.doc).value).toBe("x\n\ny");
382
+ },
383
+);
384
+
385
it("keeps the caret inside unknown dollar text across rich and plain remounts", async () => {
386
const value = "echo $HOME now";
387
await using screen = await mountEditor(value);
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+2
-2
@@ -131,7 +131,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
131
import { ComposerCodeBlockNodeView } from "./chat/ComposerCodeBlockNodeView";
132
import { resolveAssistantCitationCommentDismissal } from "./chat/assistantCitationCommentDismissal";
133
import { composerCodeBlockHighlight } from "./composerCodeBlockHighlight";
134
-import { importPastedComposerText } from "./composerInlineTokenPaste";
134
+import { importPastedComposerText, readPastedPlainText } from "./composerInlineTokenPaste";
135
import { didComposerSelectionChangeVisibly } from "./composerSelection";
136
import type { ComposerDraftContextRecords } from "./composerContextPresentation";
137
@@ -1367,7 +1367,7 @@ function ComposerPromptEditorTiptapInner(
1367
handlePaste: (view, event) => {
1368
const clipboardData = event.clipboardData;
1369
if (!clipboardData || clipboardData.files.length > 0) return false;
1370
- const pastedText = clipboardData.getData("text/plain");
1370
+ const pastedText = readPastedPlainText(clipboardData);
1371
if (!pastedText) return false;
1372
event.preventDefault();
1373
// Paste verbatim inside fences; markdown parsing would split blocks and create unsupported chips.
apps/web/src/components/composerInlineTokenPaste.test.ts
+6
@@ -56,4 +56,10 @@ describe("importPastedComposerText", () => {
56
pasted,
57
);
58
});
59
+
60
+ it("imports CRLF and CR clipboard text with LF line breaks", () => {
61
+ expect(
62
+ importPastedComposerText(clipboard({ "text/plain": "x\r\n\r\ny\rz" }), () => new Map()),
63
+ ).toBe("x\n\ny\nz");
64
+ });
65
});
apps/web/src/components/composerInlineTokenPaste.ts
+6
-1
@@ -20,6 +20,11 @@ import { readThreadShell } from "~/state/entities";
20
21
const threadTitle = (ref: ScopedThreadRef) => readThreadShell(ref)?.title;
22
23
+// Matches ProseMirror's default clipboard parser, which a custom handlePaste bypasses.
24
+export function readPastedPlainText(clipboardData: Pick<DataTransfer, "getData">): string {
25
+ return clipboardData.getData("text/plain").replace(/\r\n?/g, "\n");
26
+}
27
+
28
/** Pasted thread links count as context too, so they become chips like a copied chip does. */
29
export function readPastedComposerContext(
30
clipboardData: Pick<DataTransfer, "getData">,
@@ -65,7 +70,7 @@ export function importPastedComposerText(
70
fragment: ComposerContextClipboardFragment,
71
) => ReadonlyMap<string, string>,
72
): string {
68
- const pastedText = clipboardData.getData("text/plain");
73
+ const pastedText = readPastedPlainText(clipboardData);
74
const fragment = importContextFragment ? readPastedComposerContext(clipboardData) : null;
75
const rewrittenIds =
76
fragment && fragment.records.length > 0 ? importContextFragment!(fragment) : null;