From 634939e9a01ac47ba6f4a5322befbc0e039b1fbe Mon Sep 17 00:00:00 2001 From: Honey Paptan Date: Thu, 5 Nov 2026 01:14:10 +0530 Subject: [PATCH 01/13] fix(web): keep pasted arithmetic stars verbatim in the rich-text composer The composer's paste handler already parses pasted markdown and tags the insert as a paste for undo grouping, which also triggered Tiptap's paste rules on the parsed result. Literal * and ** left over from the parse were turned into italic and bold marks, so pasted code like (7 * 2**3 * 5)**4 reached the agent changed. Paste rules are now off for the composer. Fixes #31079 --- ...rPromptEditorTiptap.input.browser.test.tsx | 19 +++++++++++++++++++ .../components/ComposerPromptEditorTiptap.tsx | 3 +++ apps/web/src/composer-rich-text-doc.ts | 6 +----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index c59724cccf693..10323abaeb9a3 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -220,6 +220,25 @@ it("keeps unknown dollar names editable when restoring and pasting a draft", asy expect(serializeEditorDoc(editor.state.doc).value).toBe(value); }); +it("pastes arithmetic stars verbatim and still styles pasted markdown", async () => { + await using screen = await mountEditor("", true, []); + const { editor } = screen; + const paste = async (text: string) => { + await act(async () => { + editor.commands.selectAll(); + const clipboardData = new DataTransfer(); + clipboardData.setData("text/plain", text); + editor.view.dom.dispatchEvent(new ClipboardEvent("paste", { clipboardData, cancelable: true })); + }); + }; + const code = "signal = (7 * 2**3 * 5)**4"; + await paste(code); + expect(serializeEditorDoc(editor.state.doc).value).toBe(code); + await paste("a **bold** and *soft* word"); + expect(serializeEditorDoc(editor.state.doc).value).toBe("a **bold** and *soft* word"); + expect(editor.state.doc.textContent).toBe("a bold and soft word"); +}); + it("keeps the caret inside unknown dollar text across rich and plain remounts", async () => { const value = "echo $HOME now"; await using screen = await mountEditor(value); diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index 3df1e47613370..6a10a84c92ca9 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -1111,6 +1111,9 @@ function ComposerPromptEditorTiptapInner( literalText, }), editable: !disabled, + // handlePaste parses pasted markdown itself and tags the insert as a paste for undo grouping, so Tiptap's + // paste rules would parse that result a second time and turn literal `*` and `**` into marks. + enablePasteRules: false, editorProps: { attributes: editorAttributes, handleKeyDown: (view, event) => { diff --git a/apps/web/src/composer-rich-text-doc.ts b/apps/web/src/composer-rich-text-doc.ts index ae0c9441625b4..fa31d339fc91b 100644 --- a/apps/web/src/composer-rich-text-doc.ts +++ b/apps/web/src/composer-rich-text-doc.ts @@ -16,14 +16,13 @@ import { Blockquote } from "@tiptap/extension-blockquote"; import { CodeBlock } from "@tiptap/extension-code-block"; import { Heading } from "@tiptap/extension-heading"; import { HorizontalRule } from "@tiptap/extension-horizontal-rule"; -import { Italic, starInputRegex, starPasteRegex } from "@tiptap/extension-italic"; +import { Italic, starInputRegex } from "@tiptap/extension-italic"; import { type Command, type Editor, Extension, InputRule, markInputRule, - markPasteRule, mergeAttributes, } from "@tiptap/core"; import { BulletList, ListItem, OrderedList } from "@tiptap/extension-list"; @@ -278,9 +277,6 @@ export const ComposerItalicExtension = Italic.extend({ addInputRules() { return [markInputRuleOutsideCode(starInputRegex, this.type)]; }, - addPasteRules() { - return [markPasteRule({ find: starPasteRegex, type: this.type })]; - }, }); export const ComposerBoldExtension = Bold.extend({ From 9ac428eeda1375b9880a9099c0ec61fae5b55d21 Mon Sep 17 00:00:00 2001 From: Honey Paptan Date: Thu, 5 Nov 2026 01:50:05 +0530 Subject: [PATCH 02/13] style(web): format composer paste test --- .../ComposerPromptEditorTiptap.input.browser.test.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index 10323abaeb9a3..6a1dfedec3b1a 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -228,7 +228,9 @@ it("pastes arithmetic stars verbatim and still styles pasted markdown", async () editor.commands.selectAll(); const clipboardData = new DataTransfer(); clipboardData.setData("text/plain", text); - editor.view.dom.dispatchEvent(new ClipboardEvent("paste", { clipboardData, cancelable: true })); + editor.view.dom.dispatchEvent( + new ClipboardEvent("paste", { clipboardData, cancelable: true }), + ); }); }; const code = "signal = (7 * 2**3 * 5)**4"; From 93f009e6e09b211777657225e09682e0e2856b7d Mon Sep 17 00:00:00 2001 From: Honey Paptan Date: Thu, 5 Nov 2026 12:07:49 +0530 Subject: [PATCH 03/13] fix(web): parse markdown in text dropped into the composer --- ...rPromptEditorTiptap.input.browser.test.tsx | 28 ++++ .../components/ComposerPromptEditorTiptap.tsx | 158 ++++++++++-------- 2 files changed, 114 insertions(+), 72 deletions(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index 6a1dfedec3b1a..59de853bc8248 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -241,6 +241,34 @@ it("pastes arithmetic stars verbatim and still styles pasted markdown", async () expect(editor.state.doc.textContent).toBe("a bold and soft word"); }); +it("parses markdown dropped from outside and keeps dropped arithmetic verbatim", async () => { + await using screen = await mountEditor("", true, []); + const { editor } = screen; + const drop = async (text: string) => { + await act(async () => { + editor.commands.clearContent(); + const dataTransfer = new DataTransfer(); + dataTransfer.setData("text/plain", text); + const { left, top } = editor.view.coordsAtPos(1); + editor.view.dom.dispatchEvent( + new DragEvent("drop", { + dataTransfer, + clientX: left, + clientY: top + 1, + bubbles: true, + cancelable: true, + }), + ); + }); + }; + await drop("a **bold** and *soft* word"); + expect(serializeEditorDoc(editor.state.doc).value).toBe("a **bold** and *soft* word"); + expect(editor.state.doc.textContent).toBe("a bold and soft word"); + const code = "signal = (7 * 2**3 * 5)**4"; + await drop(code); + expect(serializeEditorDoc(editor.state.doc).value).toBe(code); +}); + it("keeps the caret inside unknown dollar text across rich and plain remounts", async () => { const value = "echo $HOME now"; await using screen = await mountEditor(value); diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index 6a10a84c92ca9..0a3b447fc6e65 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -1103,6 +1103,81 @@ function ComposerPromptEditorTiptapInner( "aria-placeholder": placeholder, }; + const insertClipboardText = (view: EditorView, clipboardData: DataTransfer): boolean => { + const pastedText = clipboardData.getData("text/plain"); + if (!pastedText) return false; + // Paste verbatim inside fences; markdown parsing would split blocks and create unsupported chips. + if (isInCodeBlock(view)) { + const { from, to } = view.state.selection; + view.dispatch( + markAsClipboardEdit( + view.state.tr.insertText(pastedText, from, to), + "paste", + ).scrollIntoView(), + ); + return true; + } + const importFragment = readCallbacks().importContextFragment; + let text = + !literalText && importFragment + ? importPastedComposerText(clipboardData, importFragment) + : pastedText; + const tokens = literalText ? [] : collectComposerPromptInlineTokens(`${text}\n`); + const isChip = (token: (typeof tokens)[number] | undefined) => + token?.type === "mention" || (token?.type === "skill" && skillLabelFor(token.value) !== null); + const lastToken = tokens.at(-1); + if (isChip(lastToken) && lastToken?.end === text.length) { + text += " "; + } + if (isChip(tokens[0]) && tokens[0]?.start === 0) { + const map = serializeEditorDoc(view.state.doc); + const offset = flatToMarkdown(map, pmToFlat(map, view.state.selection.from)); + if (offset > 0 && !/\s/.test(map.value[offset - 1]!)) text = ` ${text}`; + } + const { $from } = view.state.selection; + const lineBefore = $from.parent.textBetween(0, $from.parentOffset, undefined, "\uFFFC"); + const literalLength = literalText + ? 0 + : pastedPathQueryLength(lineBefore, text, readCallbacks().isPathQueryActive?.()); + const editorInstance = (view.dom as TiptapEditorHTMLElement).editor; + if (editorInstance) { + const $paste = view.state.selection.$from; + const nested = ["listItem", "taskItem", "blockquote"].some((name) => + hasAncestor($paste, name), + ); + insertMarkdownParagraphs( + text, + skillLabelFor, + { styling: richText, blocks: !nested, literalText, literalLength }, + (content) => { + editorInstance + .chain() + .command(({ tr }) => { + markAsClipboardEdit(tr, "paste"); + return true; + }) + .insertContent(content) + .command(({ tr }) => { + // Move after a pasted rule so the next keystroke cannot replace it; add a trailing line + // if needed. + const { selection } = tr; + if (!(selection instanceof NodeSelection) || !selection.node.isBlock) { + return true; + } + if (!tr.doc.resolve(selection.to).nodeAfter?.isTextblock) { + tr.insert(selection.to, tr.doc.type.schema.nodes.paragraph!.create()); + } + tr.setSelection(TextSelection.create(tr.doc, selection.to + 1)); + return true; + }) + .run(); + }, + ); + scrollTiptapCaretIntoView(editorInstance); + } + return true; + }; + const editor = useEditor( { extensions: richText ? RICH_TEXT_EXTENSIONS : PLAIN_TEXT_EXTENSIONS, @@ -1357,81 +1432,20 @@ function ComposerPromptEditorTiptapInner( handlePaste: (view, event) => { const clipboardData = event.clipboardData; if (!clipboardData || clipboardData.files.length > 0) return false; - const pastedText = clipboardData.getData("text/plain"); - if (!pastedText) return false; + if (!insertClipboardText(view, clipboardData)) return false; event.preventDefault(); - // Paste verbatim inside fences; markdown parsing would split blocks and create unsupported chips. - if (isInCodeBlock(view)) { - const { from, to } = view.state.selection; - view.dispatch( - markAsClipboardEdit( - view.state.tr.insertText(pastedText, from, to), - "paste", - ).scrollIntoView(), - ); - return true; - } - const importFragment = readCallbacks().importContextFragment; - let text = - !literalText && importFragment - ? importPastedComposerText(clipboardData, importFragment) - : pastedText; - const tokens = literalText ? [] : collectComposerPromptInlineTokens(`${text}\n`); - const isChip = (token: (typeof tokens)[number] | undefined) => - token?.type === "mention" || - (token?.type === "skill" && skillLabelFor(token.value) !== null); - const lastToken = tokens.at(-1); - if (isChip(lastToken) && lastToken?.end === text.length) { - text += " "; - } - if (isChip(tokens[0]) && tokens[0]?.start === 0) { - const map = serializeEditorDoc(view.state.doc); - const offset = flatToMarkdown(map, pmToFlat(map, view.state.selection.from)); - if (offset > 0 && !/\s/.test(map.value[offset - 1]!)) text = ` ${text}`; - } - const { $from } = view.state.selection; - const lineBefore = $from.parent.textBetween(0, $from.parentOffset, undefined, "\uFFFC"); - const literalLength = literalText - ? 0 - : pastedPathQueryLength(lineBefore, text, readCallbacks().isPathQueryActive?.()); - const editorInstance = (view.dom as TiptapEditorHTMLElement).editor; - if (editorInstance) { - const $paste = view.state.selection.$from; - const nested = ["listItem", "taskItem", "blockquote"].some((name) => - hasAncestor($paste, name), - ); - insertMarkdownParagraphs( - text, - skillLabelFor, - { styling: richText, blocks: !nested, literalText, literalLength }, - (content) => { - editorInstance - .chain() - .command(({ tr }) => { - markAsClipboardEdit(tr, "paste"); - return true; - }) - .insertContent(content) - .command(({ tr }) => { - // Move after a pasted rule so the next keystroke cannot replace it; add a trailing line - // if needed. - const { selection } = tr; - if (!(selection instanceof NodeSelection) || !selection.node.isBlock) { - return true; - } - if (!tr.doc.resolve(selection.to).nodeAfter?.isTextblock) { - tr.insert(selection.to, tr.doc.type.schema.nodes.paragraph!.create()); - } - tr.setSelection(TextSelection.create(tr.doc, selection.to + 1)); - return true; - }) - .run(); - }, - ); - scrollTiptapCaretIntoView(editorInstance); - } return true; }, + handleDrop: (view, event, _slice, moved) => { + const data = event.dataTransfer; + if (moved || !data || data.files.length > 0 || !data.getData("text/plain")) return false; + const target = view.posAtCoords({ left: event.clientX, top: event.clientY }); + if (!target) return false; + view.dispatch( + view.state.tr.setSelection(TextSelection.near(view.state.doc.resolve(target.pos))), + ); + return insertClipboardText(view, data); + }, }, onUpdate: ({ editor: updated, transaction }) => { // Undo can restore a chip for a skill the current provider no longer offers. From dd2b556e9baa246c6f72625d554e80056baa588b Mon Sep 17 00:00:00 2001 From: Honey Paptan Date: Thu, 5 Nov 2026 13:18:28 +0530 Subject: [PATCH 04/13] fix(web): leave composer drags that start inside the editor to ProseMirror --- ...rPromptEditorTiptap.input.browser.test.tsx | 25 +++++++++++++++++++ .../components/ComposerPromptEditorTiptap.tsx | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index 59de853bc8248..3f1de6c2624e7 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -269,6 +269,31 @@ it("parses markdown dropped from outside and keeps dropped arithmetic verbatim", expect(serializeEditorDoc(editor.state.doc).value).toBe(code); }); +it("leaves drops that started inside the editor to ProseMirror", async () => { + await using screen = await mountEditor("", true, []); + const { editor } = screen; + let handled: unknown; + await act(async () => { + const dataTransfer = new DataTransfer(); + dataTransfer.setData("text/plain", "a **bold** word"); + const { left, top } = editor.view.coordsAtPos(1); + const event = new DragEvent("drop", { + dataTransfer, + clientX: left, + clientY: top + 1, + bubbles: true, + cancelable: true, + }); + editor.view.dragging = { slice: editor.state.doc.slice(0, 0), move: false }; + handled = editor.view.someProp("handleDrop", (handleDrop) => + handleDrop(editor.view, event, editor.state.doc.slice(0, 0), false), + ); + editor.view.dragging = null; + }); + expect(handled).toBeFalsy(); + expect(serializeEditorDoc(editor.state.doc).value).toBe(""); +}); + it("keeps the caret inside unknown dollar text across rich and plain remounts", async () => { const value = "echo $HOME now"; await using screen = await mountEditor(value); diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index 0a3b447fc6e65..1d3404070bc15 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -1438,7 +1438,8 @@ function ComposerPromptEditorTiptapInner( }, handleDrop: (view, event, _slice, moved) => { const data = event.dataTransfer; - if (moved || !data || data.files.length > 0 || !data.getData("text/plain")) return false; + if (moved || view.dragging || !data || data.files.length > 0) return false; + if (!data.getData("text/plain")) return false; const target = view.posAtCoords({ left: event.clientX, top: event.clientY }); if (!target) return false; view.dispatch( From b4e38a8dd2e5ae63ffbb07fc37c372b46b82b4cd Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 03:27:53 +0000 Subject: [PATCH 05/13] test(web): drive the internal-drag case through a real drop event AI-assisted; verified with the tests and tools listed above. --- ...rPromptEditorTiptap.input.browser.test.tsx | 27 +++---------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index 48af6f64d1fed..8448f7d99a9b8 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -368,30 +368,9 @@ it("parses markdown dropped from outside and keeps dropped arithmetic verbatim", const code = "signal = (7 * 2**3 * 5)**4"; await drop(code); expect(serializeEditorDoc(editor.state.doc).value).toBe(code); -}); - -it("leaves drops that started inside the editor to ProseMirror", async () => { - await using screen = await mountEditor("", true, []); - const { editor } = screen; - let handled: unknown; - await act(async () => { - const dataTransfer = new DataTransfer(); - dataTransfer.setData("text/plain", "a **bold** word"); - const { left, top } = editor.view.coordsAtPos(1); - const event = new DragEvent("drop", { - dataTransfer, - clientX: left, - clientY: top + 1, - bubbles: true, - cancelable: true, - }); - editor.view.dragging = { slice: editor.state.doc.slice(0, 0), move: false }; - handled = editor.view.someProp("handleDrop", (handleDrop) => - handleDrop(editor.view, event, editor.state.doc.slice(0, 0), false), - ); - editor.view.dragging = null; - }); - expect(handled).toBeFalsy(); + // A drag that started inside the editor is ProseMirror's move, not an external text drop. + editor.view.dragging = { slice: editor.state.doc.slice(0, 0), move: false }; + await drop("a **bold** word"); expect(serializeEditorDoc(editor.state.doc).value).toBe(""); }); From fd3c3cb70b7f823a481cc1c987847dc8cc50b909 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 03:54:58 +0000 Subject: [PATCH 06/13] fix(web): leave text drops to ProseMirror so the composer takes focus The custom handleDrop returned before ProseMirror's own view.focus(), so typing after an external drop went to the previously focused control. Disabling paste rules already keeps dropped arithmetic verbatim. AI-assisted; verified with the tests and tools listed above. --- ...rPromptEditorTiptap.input.browser.test.tsx | 43 ++-- .../components/ComposerPromptEditorTiptap.tsx | 202 ++++++++---------- 2 files changed, 110 insertions(+), 135 deletions(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index 8448f7d99a9b8..7a904566999c7 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -342,36 +342,27 @@ it("pastes arithmetic stars verbatim and still styles pasted markdown", async () expect(editor.state.doc.textContent).toBe("a bold and soft word"); }); -it("parses markdown dropped from outside and keeps dropped arithmetic verbatim", async () => { +it("keeps dropped arithmetic verbatim and focuses the editor", async () => { await using screen = await mountEditor("", true, []); const { editor } = screen; - const drop = async (text: string) => { - await act(async () => { - editor.commands.clearContent(); - const dataTransfer = new DataTransfer(); - dataTransfer.setData("text/plain", text); - const { left, top } = editor.view.coordsAtPos(1); - editor.view.dom.dispatchEvent( - new DragEvent("drop", { - dataTransfer, - clientX: left, - clientY: top + 1, - bubbles: true, - cancelable: true, - }), - ); - }); - }; - await drop("a **bold** and *soft* word"); - expect(serializeEditorDoc(editor.state.doc).value).toBe("a **bold** and *soft* word"); - expect(editor.state.doc.textContent).toBe("a bold and soft word"); const code = "signal = (7 * 2**3 * 5)**4"; - await drop(code); + await act(async () => { + editor.view.dom.blur(); + const dataTransfer = new DataTransfer(); + dataTransfer.setData("text/plain", code); + const { left, top } = editor.view.coordsAtPos(1); + editor.view.dom.dispatchEvent( + new DragEvent("drop", { + dataTransfer, + clientX: left, + clientY: top + 1, + bubbles: true, + cancelable: true, + }), + ); + }); expect(serializeEditorDoc(editor.state.doc).value).toBe(code); - // A drag that started inside the editor is ProseMirror's move, not an external text drop. - editor.view.dragging = { slice: editor.state.doc.slice(0, 0), move: false }; - await drop("a **bold** word"); - expect(serializeEditorDoc(editor.state.doc).value).toBe(""); + expect(editor.view.hasFocus()).toBe(true); }); it("keeps the caret inside unknown dollar text across rich and plain remounts", async () => { diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index da3eb75a0786d..aa99d27c6f2a1 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -1098,101 +1098,6 @@ function ComposerPromptEditorTiptapInner( "aria-placeholder": placeholder, }; - const insertClipboardText = (view: EditorView, clipboardData: DataTransfer): boolean => { - const pastedText = clipboardData.getData("text/plain"); - if (!pastedText) return false; - // Paste verbatim inside fences; markdown parsing would split blocks and create unsupported chips. - if (isInCodeBlock(view)) { - const { from, to } = view.state.selection; - view.dispatch( - markAsClipboardEdit( - view.state.tr.insertText(pastedText, from, to), - "paste", - ).scrollIntoView(), - ); - return true; - } - // Shown Markdown source is parsed when the caret leaves, so paste one line into it as text. - const sourceType = view.state.schema.marks[MARKDOWN_SOURCE_MARK]; - const { from: pasteFrom, to: pasteTo, $from: $pasteFrom } = view.state.selection; - if ( - sourceType?.isInSet($pasteFrom.marks()) && - !pastedText.includes("\n") && - collectComposerPromptInlineTokens(`${pastedText}\n`).length === 0 - ) { - view.dispatch( - markAsClipboardEdit( - view.state.tr.insertText(pastedText, pasteFrom, pasteTo), - "paste", - ).scrollIntoView(), - ); - return true; - } - const importFragment = readCallbacks().importContextFragment; - let text = - !literalText && importFragment - ? importPastedComposerText(clipboardData, importFragment) - : pastedText; - const tokens = literalText ? [] : collectComposerPromptInlineTokens(`${text}\n`); - const isChip = (token: (typeof tokens)[number] | undefined) => - token?.type === "mention" || - (token?.type === "skill" && skillLabelFor(token.value) !== null) || - (token?.type === "model" && isKnownModel(token.instanceId, token.model)); - const lastToken = tokens.at(-1); - if (isChip(lastToken) && lastToken?.end === text.length) { - text += " "; - } - if (isChip(tokens[0]) && tokens[0]?.start === 0) { - const map = serializeEditorDoc(view.state.doc); - const offset = flatToMarkdown(map, pmToFlat(map, view.state.selection.from)); - if (offset > 0 && !/\s/.test(map.value[offset - 1]!)) text = ` ${text}`; - } - const { $from } = view.state.selection; - const lineBefore = $from.parent.textBetween(0, $from.parentOffset, undefined, "\uFFFC"); - const literalLength = literalText - ? 0 - : pastedPathQueryLength(lineBefore, text, readCallbacks().isPathQueryActive?.()); - const editorInstance = (view.dom as TiptapEditorHTMLElement).editor; - if (editorInstance) { - const $paste = view.state.selection.$from; - const nested = ["listItem", "taskItem", "blockquote"].some((name) => - hasAncestor($paste, name), - ); - insertMarkdownParagraphs( - text, - skillLabelFor, - { styling: richText, blocks: !nested, literalText, literalLength, isKnownModel }, - (content) => { - editorInstance - .chain() - .command(({ tr }) => { - markAsClipboardEdit(tr, "paste"); - return true; - }) - // Pasted chips and lines would split shown Markdown, so parse it first. - .command(collapseShownMarkdownSource) - .insertContent(content) - .command(({ tr }) => { - // Move after a pasted rule so the next keystroke cannot replace it; add a trailing line - // if needed. - const { selection } = tr; - if (!(selection instanceof NodeSelection) || !selection.node.isBlock) { - return true; - } - if (!tr.doc.resolve(selection.to).nodeAfter?.isTextblock) { - tr.insert(selection.to, tr.doc.type.schema.nodes.paragraph!.create()); - } - tr.setSelection(TextSelection.create(tr.doc, selection.to + 1)); - return true; - }) - .run(); - }, - ); - scrollTiptapCaretIntoView(editorInstance); - } - return true; - }; - const editor = useEditor( { extensions: richText ? RICH_TEXT_EXTENSIONS : PLAIN_TEXT_EXTENSIONS, @@ -1202,8 +1107,8 @@ function ComposerPromptEditorTiptapInner( isKnownModel: (instanceId, model) => modelKeys.has(modelMentionKey(instanceId, model)), }), editable: !disabled, - // handlePaste parses pasted markdown itself and tags the insert as a paste for undo grouping, so Tiptap's - // paste rules would parse that result a second time and turn literal `*` and `**` into marks. + // handlePaste parses pasted markdown itself, so Tiptap's paste rules would parse that result a second + // time and turn literal `*` and `**` into marks. enablePasteRules: false, editorProps: { attributes: editorAttributes, @@ -1462,21 +1367,100 @@ function ComposerPromptEditorTiptapInner( handlePaste: (view, event) => { const clipboardData = event.clipboardData; if (!clipboardData || clipboardData.files.length > 0) return false; - if (!insertClipboardText(view, clipboardData)) return false; + const pastedText = clipboardData.getData("text/plain"); + if (!pastedText) return false; event.preventDefault(); + // Paste verbatim inside fences; markdown parsing would split blocks and create unsupported chips. + if (isInCodeBlock(view)) { + const { from, to } = view.state.selection; + view.dispatch( + markAsClipboardEdit( + view.state.tr.insertText(pastedText, from, to), + "paste", + ).scrollIntoView(), + ); + return true; + } + // Shown Markdown source is parsed when the caret leaves, so paste one line into it as text. + const sourceType = view.state.schema.marks[MARKDOWN_SOURCE_MARK]; + const { from: pasteFrom, to: pasteTo, $from: $pasteFrom } = view.state.selection; + if ( + sourceType?.isInSet($pasteFrom.marks()) && + !pastedText.includes("\n") && + collectComposerPromptInlineTokens(`${pastedText}\n`).length === 0 + ) { + view.dispatch( + markAsClipboardEdit( + view.state.tr.insertText(pastedText, pasteFrom, pasteTo), + "paste", + ).scrollIntoView(), + ); + return true; + } + const importFragment = readCallbacks().importContextFragment; + let text = + !literalText && importFragment + ? importPastedComposerText(clipboardData, importFragment) + : pastedText; + const tokens = literalText ? [] : collectComposerPromptInlineTokens(`${text}\n`); + const isChip = (token: (typeof tokens)[number] | undefined) => + token?.type === "mention" || + (token?.type === "skill" && skillLabelFor(token.value) !== null) || + (token?.type === "model" && isKnownModel(token.instanceId, token.model)); + const lastToken = tokens.at(-1); + if (isChip(lastToken) && lastToken?.end === text.length) { + text += " "; + } + if (isChip(tokens[0]) && tokens[0]?.start === 0) { + const map = serializeEditorDoc(view.state.doc); + const offset = flatToMarkdown(map, pmToFlat(map, view.state.selection.from)); + if (offset > 0 && !/\s/.test(map.value[offset - 1]!)) text = ` ${text}`; + } + const { $from } = view.state.selection; + const lineBefore = $from.parent.textBetween(0, $from.parentOffset, undefined, "\uFFFC"); + const literalLength = literalText + ? 0 + : pastedPathQueryLength(lineBefore, text, readCallbacks().isPathQueryActive?.()); + const editorInstance = (view.dom as TiptapEditorHTMLElement).editor; + if (editorInstance) { + const $paste = view.state.selection.$from; + const nested = ["listItem", "taskItem", "blockquote"].some((name) => + hasAncestor($paste, name), + ); + insertMarkdownParagraphs( + text, + skillLabelFor, + { styling: richText, blocks: !nested, literalText, literalLength, isKnownModel }, + (content) => { + editorInstance + .chain() + .command(({ tr }) => { + markAsClipboardEdit(tr, "paste"); + return true; + }) + // Pasted chips and lines would split shown Markdown, so parse it first. + .command(collapseShownMarkdownSource) + .insertContent(content) + .command(({ tr }) => { + // Move after a pasted rule so the next keystroke cannot replace it; add a trailing line + // if needed. + const { selection } = tr; + if (!(selection instanceof NodeSelection) || !selection.node.isBlock) { + return true; + } + if (!tr.doc.resolve(selection.to).nodeAfter?.isTextblock) { + tr.insert(selection.to, tr.doc.type.schema.nodes.paragraph!.create()); + } + tr.setSelection(TextSelection.create(tr.doc, selection.to + 1)); + return true; + }) + .run(); + }, + ); + scrollTiptapCaretIntoView(editorInstance); + } return true; }, - handleDrop: (view, event, _slice, moved) => { - const data = event.dataTransfer; - if (moved || view.dragging || !data || data.files.length > 0) return false; - if (!data.getData("text/plain")) return false; - const target = view.posAtCoords({ left: event.clientX, top: event.clientY }); - if (!target) return false; - view.dispatch( - view.state.tr.setSelection(TextSelection.near(view.state.doc.resolve(target.pos))), - ); - return insertClipboardText(view, data); - }, }, onUpdate: ({ editor: updated, transaction }) => { // Undo can restore a chip for a skill or model the environment no longer offers. From 7d3f96ac8f8a1de73811548b78ec14604a3dd953 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 04:27:18 +0000 Subject: [PATCH 07/13] fix(web): style markdown dropped into the composer and focus it Dropping the custom drop handler left dropped Markdown literal, which main styled through paste rules. Restore the shared insertion for external text drops and focus the view first, since handling the drop skips ProseMirror's own focus call. AI-assisted; verified with the tests and tools listed above. --- ...rPromptEditorTiptap.input.browser.test.tsx | 45 ++-- .../components/ComposerPromptEditorTiptap.tsx | 204 ++++++++++-------- 2 files changed, 139 insertions(+), 110 deletions(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index 7a904566999c7..f738a8d5e31ad 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -342,27 +342,38 @@ it("pastes arithmetic stars verbatim and still styles pasted markdown", async () expect(editor.state.doc.textContent).toBe("a bold and soft word"); }); -it("keeps dropped arithmetic verbatim and focuses the editor", async () => { +it("parses markdown dropped from outside, keeps dropped arithmetic verbatim, and focuses", async () => { await using screen = await mountEditor("", true, []); const { editor } = screen; + const drop = async (text: string) => { + await act(async () => { + editor.commands.clearContent(); + editor.view.dom.blur(); + const dataTransfer = new DataTransfer(); + dataTransfer.setData("text/plain", text); + const { left, top } = editor.view.coordsAtPos(1); + editor.view.dom.dispatchEvent( + new DragEvent("drop", { + dataTransfer, + clientX: left, + clientY: top + 1, + bubbles: true, + cancelable: true, + }), + ); + }); + }; + await drop("a **bold** and *soft* word"); + expect(serializeEditorDoc(editor.state.doc).value).toBe("a **bold** and *soft* word"); + expect(editor.state.doc.textContent).toBe("a bold and soft word"); + expect(editor.view.hasFocus()).toBe(true); const code = "signal = (7 * 2**3 * 5)**4"; - await act(async () => { - editor.view.dom.blur(); - const dataTransfer = new DataTransfer(); - dataTransfer.setData("text/plain", code); - const { left, top } = editor.view.coordsAtPos(1); - editor.view.dom.dispatchEvent( - new DragEvent("drop", { - dataTransfer, - clientX: left, - clientY: top + 1, - bubbles: true, - cancelable: true, - }), - ); - }); + await drop(code); expect(serializeEditorDoc(editor.state.doc).value).toBe(code); - expect(editor.view.hasFocus()).toBe(true); + // A drag that started inside the editor is ProseMirror's move, not an external text drop. + editor.view.dragging = { slice: editor.state.doc.slice(0, 0), move: false }; + await drop("a **bold** word"); + expect(serializeEditorDoc(editor.state.doc).value).toBe(""); }); it("keeps the caret inside unknown dollar text across rich and plain remounts", async () => { diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index aa99d27c6f2a1..e16bfa0add523 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -1098,6 +1098,101 @@ function ComposerPromptEditorTiptapInner( "aria-placeholder": placeholder, }; + const insertClipboardText = (view: EditorView, clipboardData: DataTransfer): boolean => { + const pastedText = clipboardData.getData("text/plain"); + if (!pastedText) return false; + // Paste verbatim inside fences; markdown parsing would split blocks and create unsupported chips. + if (isInCodeBlock(view)) { + const { from, to } = view.state.selection; + view.dispatch( + markAsClipboardEdit( + view.state.tr.insertText(pastedText, from, to), + "paste", + ).scrollIntoView(), + ); + return true; + } + // Shown Markdown source is parsed when the caret leaves, so paste one line into it as text. + const sourceType = view.state.schema.marks[MARKDOWN_SOURCE_MARK]; + const { from: pasteFrom, to: pasteTo, $from: $pasteFrom } = view.state.selection; + if ( + sourceType?.isInSet($pasteFrom.marks()) && + !pastedText.includes("\n") && + collectComposerPromptInlineTokens(`${pastedText}\n`).length === 0 + ) { + view.dispatch( + markAsClipboardEdit( + view.state.tr.insertText(pastedText, pasteFrom, pasteTo), + "paste", + ).scrollIntoView(), + ); + return true; + } + const importFragment = readCallbacks().importContextFragment; + let text = + !literalText && importFragment + ? importPastedComposerText(clipboardData, importFragment) + : pastedText; + const tokens = literalText ? [] : collectComposerPromptInlineTokens(`${text}\n`); + const isChip = (token: (typeof tokens)[number] | undefined) => + token?.type === "mention" || + (token?.type === "skill" && skillLabelFor(token.value) !== null) || + (token?.type === "model" && isKnownModel(token.instanceId, token.model)); + const lastToken = tokens.at(-1); + if (isChip(lastToken) && lastToken?.end === text.length) { + text += " "; + } + if (isChip(tokens[0]) && tokens[0]?.start === 0) { + const map = serializeEditorDoc(view.state.doc); + const offset = flatToMarkdown(map, pmToFlat(map, view.state.selection.from)); + if (offset > 0 && !/\s/.test(map.value[offset - 1]!)) text = ` ${text}`; + } + const { $from } = view.state.selection; + const lineBefore = $from.parent.textBetween(0, $from.parentOffset, undefined, "\uFFFC"); + const literalLength = literalText + ? 0 + : pastedPathQueryLength(lineBefore, text, readCallbacks().isPathQueryActive?.()); + const editorInstance = (view.dom as TiptapEditorHTMLElement).editor; + if (editorInstance) { + const $paste = view.state.selection.$from; + const nested = ["listItem", "taskItem", "blockquote"].some((name) => + hasAncestor($paste, name), + ); + insertMarkdownParagraphs( + text, + skillLabelFor, + { styling: richText, blocks: !nested, literalText, literalLength, isKnownModel }, + (content) => { + editorInstance + .chain() + .command(({ tr }) => { + markAsClipboardEdit(tr, "paste"); + return true; + }) + // Pasted chips and lines would split shown Markdown, so parse it first. + .command(collapseShownMarkdownSource) + .insertContent(content) + .command(({ tr }) => { + // Move after a pasted rule so the next keystroke cannot replace it; add a trailing line + // if needed. + const { selection } = tr; + if (!(selection instanceof NodeSelection) || !selection.node.isBlock) { + return true; + } + if (!tr.doc.resolve(selection.to).nodeAfter?.isTextblock) { + tr.insert(selection.to, tr.doc.type.schema.nodes.paragraph!.create()); + } + tr.setSelection(TextSelection.create(tr.doc, selection.to + 1)); + return true; + }) + .run(); + }, + ); + scrollTiptapCaretIntoView(editorInstance); + } + return true; + }; + const editor = useEditor( { extensions: richText ? RICH_TEXT_EXTENSIONS : PLAIN_TEXT_EXTENSIONS, @@ -1107,8 +1202,8 @@ function ComposerPromptEditorTiptapInner( isKnownModel: (instanceId, model) => modelKeys.has(modelMentionKey(instanceId, model)), }), editable: !disabled, - // handlePaste parses pasted markdown itself, so Tiptap's paste rules would parse that result a second - // time and turn literal `*` and `**` into marks. + // handlePaste parses pasted markdown itself and tags the insert as a paste for undo grouping, so Tiptap's + // paste rules would parse that result a second time and turn literal `*` and `**` into marks. enablePasteRules: false, editorProps: { attributes: editorAttributes, @@ -1367,100 +1462,23 @@ function ComposerPromptEditorTiptapInner( handlePaste: (view, event) => { const clipboardData = event.clipboardData; if (!clipboardData || clipboardData.files.length > 0) return false; - const pastedText = clipboardData.getData("text/plain"); - if (!pastedText) return false; + if (!insertClipboardText(view, clipboardData)) return false; event.preventDefault(); - // Paste verbatim inside fences; markdown parsing would split blocks and create unsupported chips. - if (isInCodeBlock(view)) { - const { from, to } = view.state.selection; - view.dispatch( - markAsClipboardEdit( - view.state.tr.insertText(pastedText, from, to), - "paste", - ).scrollIntoView(), - ); - return true; - } - // Shown Markdown source is parsed when the caret leaves, so paste one line into it as text. - const sourceType = view.state.schema.marks[MARKDOWN_SOURCE_MARK]; - const { from: pasteFrom, to: pasteTo, $from: $pasteFrom } = view.state.selection; - if ( - sourceType?.isInSet($pasteFrom.marks()) && - !pastedText.includes("\n") && - collectComposerPromptInlineTokens(`${pastedText}\n`).length === 0 - ) { - view.dispatch( - markAsClipboardEdit( - view.state.tr.insertText(pastedText, pasteFrom, pasteTo), - "paste", - ).scrollIntoView(), - ); - return true; - } - const importFragment = readCallbacks().importContextFragment; - let text = - !literalText && importFragment - ? importPastedComposerText(clipboardData, importFragment) - : pastedText; - const tokens = literalText ? [] : collectComposerPromptInlineTokens(`${text}\n`); - const isChip = (token: (typeof tokens)[number] | undefined) => - token?.type === "mention" || - (token?.type === "skill" && skillLabelFor(token.value) !== null) || - (token?.type === "model" && isKnownModel(token.instanceId, token.model)); - const lastToken = tokens.at(-1); - if (isChip(lastToken) && lastToken?.end === text.length) { - text += " "; - } - if (isChip(tokens[0]) && tokens[0]?.start === 0) { - const map = serializeEditorDoc(view.state.doc); - const offset = flatToMarkdown(map, pmToFlat(map, view.state.selection.from)); - if (offset > 0 && !/\s/.test(map.value[offset - 1]!)) text = ` ${text}`; - } - const { $from } = view.state.selection; - const lineBefore = $from.parent.textBetween(0, $from.parentOffset, undefined, "\uFFFC"); - const literalLength = literalText - ? 0 - : pastedPathQueryLength(lineBefore, text, readCallbacks().isPathQueryActive?.()); - const editorInstance = (view.dom as TiptapEditorHTMLElement).editor; - if (editorInstance) { - const $paste = view.state.selection.$from; - const nested = ["listItem", "taskItem", "blockquote"].some((name) => - hasAncestor($paste, name), - ); - insertMarkdownParagraphs( - text, - skillLabelFor, - { styling: richText, blocks: !nested, literalText, literalLength, isKnownModel }, - (content) => { - editorInstance - .chain() - .command(({ tr }) => { - markAsClipboardEdit(tr, "paste"); - return true; - }) - // Pasted chips and lines would split shown Markdown, so parse it first. - .command(collapseShownMarkdownSource) - .insertContent(content) - .command(({ tr }) => { - // Move after a pasted rule so the next keystroke cannot replace it; add a trailing line - // if needed. - const { selection } = tr; - if (!(selection instanceof NodeSelection) || !selection.node.isBlock) { - return true; - } - if (!tr.doc.resolve(selection.to).nodeAfter?.isTextblock) { - tr.insert(selection.to, tr.doc.type.schema.nodes.paragraph!.create()); - } - tr.setSelection(TextSelection.create(tr.doc, selection.to + 1)); - return true; - }) - .run(); - }, - ); - scrollTiptapCaretIntoView(editorInstance); - } return true; }, + handleDrop: (view, event, _slice, moved) => { + const data = event.dataTransfer; + if (moved || view.dragging || !data || data.files.length > 0) return false; + if (!data.getData("text/plain")) return false; + const target = view.posAtCoords({ left: event.clientX, top: event.clientY }); + if (!target) return false; + view.dispatch( + view.state.tr.setSelection(TextSelection.near(view.state.doc.resolve(target.pos))), + ); + // Handling the drop skips ProseMirror's own focus call, so typing would go to the previous control. + view.focus(); + return insertClipboardText(view, data); + }, }, onUpdate: ({ editor: updated, transaction }) => { // Undo can restore a chip for a skill or model the environment no longer offers. From fcf6993adcce03b5860d284fe156be4b043fa169 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 04:41:20 +0000 Subject: [PATCH 08/13] fix(web): keep formatting of HTML dropped into the composer The drop handler took over every drop with text/plain and discarded the slice ProseMirror parsed from text/html. Handle plain-text-only drops and leave HTML drops to ProseMirror, as main does. AI-assisted; verified with the tests and tools listed above. --- .../ComposerPromptEditorTiptap.input.browser.test.tsx | 5 ++++- apps/web/src/components/ComposerPromptEditorTiptap.tsx | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index f738a8d5e31ad..5bbe94d4a909d 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -345,12 +345,13 @@ it("pastes arithmetic stars verbatim and still styles pasted markdown", async () it("parses markdown dropped from outside, keeps dropped arithmetic verbatim, and focuses", async () => { await using screen = await mountEditor("", true, []); const { editor } = screen; - const drop = async (text: string) => { + const drop = async (text: string, html?: string) => { await act(async () => { editor.commands.clearContent(); editor.view.dom.blur(); const dataTransfer = new DataTransfer(); dataTransfer.setData("text/plain", text); + if (html) dataTransfer.setData("text/html", html); const { left, top } = editor.view.coordsAtPos(1); editor.view.dom.dispatchEvent( new DragEvent("drop", { @@ -367,6 +368,8 @@ it("parses markdown dropped from outside, keeps dropped arithmetic verbatim, and expect(serializeEditorDoc(editor.state.doc).value).toBe("a **bold** and *soft* word"); expect(editor.state.doc.textContent).toBe("a bold and soft word"); expect(editor.view.hasFocus()).toBe(true); + await drop("bold", "

bold

"); + expect(serializeEditorDoc(editor.state.doc).value).toBe("**bold**"); const code = "signal = (7 * 2**3 * 5)**4"; await drop(code); expect(serializeEditorDoc(editor.state.doc).value).toBe(code); diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index e16bfa0add523..fa409fdf6ab70 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -1469,7 +1469,8 @@ function ComposerPromptEditorTiptapInner( handleDrop: (view, event, _slice, moved) => { const data = event.dataTransfer; if (moved || view.dragging || !data || data.files.length > 0) return false; - if (!data.getData("text/plain")) return false; + // ProseMirror already parses an HTML drop into marks; only plain-text drops need Markdown parsing. + if (!data.getData("text/plain") || data.getData("text/html")) return false; const target = view.posAtCoords({ left: event.clientX, top: event.clientY }); if (!target) return false; view.dispatch( From b0659a61448c5e2ee45e2bf0c88f36fbf9ec0825 Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:18:37 -0800 Subject: [PATCH 09/13] fix(web): dropped text is parsed like pasted text in the composer main (#36363) already keeps paste rules off the composer's own paste. Text dropped from outside the editor still went through ProseMirror's default drop, where Tiptap's paste rules turned literal `*` and `**` into marks and Markdown skipped the composer's parser. Drops now share the paste handler's insertion path at the drop position, and paste rules are off since the composer parses pasted and dropped text itself. Files and drags that start inside the editor keep the default drop. Co-Authored-By: Claude Opus 5.5 --- ...rPromptEditorTiptap.input.browser.test.tsx | 28 +++ .../components/ComposerPromptEditorTiptap.tsx | 202 ++++++++++-------- 2 files changed, 139 insertions(+), 91 deletions(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index f58155ae4559e..cd80bf910fb52 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -555,6 +555,7 @@ it("keeps unknown dollar names editable when restoring and pasting a draft", asy it.each([ "Read https://example.com/_handle_/status/1 and open src/__test__.tsx", "see `**x**` now", + "signal = (7 * 2**3 * 5)**4", ])("sends pasted %s as pasted", async (pasted) => { await using screen = await mountEditor(""); const { editor } = screen; @@ -566,6 +567,33 @@ it.each([ expect(serializeEditorDoc(editor.state.doc).value).toBe(pasted); }); +// regression: #31079 paste rules restyled dropped text, and dropped Markdown skipped the composer's parser +it.each([ + // Shown bold like the same paste; the sent text stays verbatim. + ["signal = (7 * 2**3 * 5)**4", "signal = (7 * 23 * 5)4"], + ["a **bold** and *soft* word", "a bold and soft word"], +])("drops %s like a paste", async (dropped, shown) => { + await using screen = await mountEditor(""); + const { editor } = screen; + await act(async () => { + const dataTransfer = new DataTransfer(); + dataTransfer.setData("text/plain", dropped); + const { left, top } = editor.view.coordsAtPos(1); + editor.view.dom.dispatchEvent( + new DragEvent("drop", { + dataTransfer, + clientX: left, + clientY: top + 1, + bubbles: true, + cancelable: true, + }), + ); + }); + expect(serializeEditorDoc(editor.state.doc).value).toBe(dropped); + expect(editor.state.doc.textContent).toBe(shown); + expect(editor.view.hasFocus()).toBe(true); +}); + it.each([ ["**DEV**", "**DEV**!"], ["*DEV*", "*DEV*!"], diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index 8ce568c117dce..188bdc1a58fda 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -1160,6 +1160,101 @@ function ComposerPromptEditorTiptapInner( "aria-placeholder": placeholder, }; + const insertClipboardText = (view: EditorView, clipboardData: DataTransfer): boolean => { + const pastedText = readPastedPlainText(clipboardData); + if (!pastedText) return false; + // Paste verbatim inside fences; markdown parsing would split blocks and create unsupported chips. + if (isInCodeBlock(view)) { + const { from, to } = view.state.selection; + view.dispatch( + markAsClipboardEdit( + view.state.tr.insertText(pastedText, from, to), + "paste", + ).scrollIntoView(), + ); + return true; + } + // Shown Markdown source is parsed when the caret leaves, so paste one line into it as text. + const sourceType = view.state.schema.marks[MARKDOWN_SOURCE_MARK]; + const { from: pasteFrom, to: pasteTo, $from: $pasteFrom } = view.state.selection; + if ( + sourceType?.isInSet($pasteFrom.marks()) && + !pastedText.includes("\n") && + collectComposerPromptInlineTokens(`${pastedText}\n`).length === 0 + ) { + view.dispatch( + markAsClipboardEdit( + view.state.tr.insertText(pastedText, pasteFrom, pasteTo), + "paste", + ).scrollIntoView(), + ); + return true; + } + const importFragment = readCallbacks().importContextFragment; + let text = + !literalText && importFragment + ? importPastedComposerText(clipboardData, importFragment) + : pastedText; + const tokens = literalText ? [] : collectComposerPromptInlineTokens(`${text}\n`); + const isChip = (token: (typeof tokens)[number] | undefined) => + token?.type === "mention" || + (token?.type === "skill" && skillLabelFor(token.value) !== null) || + (token?.type === "model" && isKnownModel(token.instanceId, token.model)); + const lastToken = tokens.at(-1); + if (isChip(lastToken) && lastToken?.end === text.length) { + text += " "; + } + if (isChip(tokens[0]) && tokens[0]?.start === 0) { + const map = serializeEditorDoc(view.state.doc); + const offset = flatToMarkdown(map, pmToFlat(map, view.state.selection.from)); + if (offset > 0 && !/\s/.test(map.value[offset - 1]!)) text = ` ${text}`; + } + const { $from } = view.state.selection; + const lineBefore = $from.parent.textBetween(0, $from.parentOffset, undefined, "\uFFFC"); + const literalLength = literalText + ? 0 + : pastedPathQueryLength(lineBefore, text, readCallbacks().isPathQueryActive?.()); + const editorInstance = (view.dom as TiptapEditorHTMLElement).editor; + if (editorInstance) { + const $paste = view.state.selection.$from; + const nested = ["listItem", "taskItem", "blockquote"].some((name) => + hasAncestor($paste, name), + ); + insertMarkdownParagraphs( + text, + skillLabelFor, + { styling: richText, blocks: !nested, literalText, literalLength, isKnownModel }, + (content) => { + editorInstance + .chain() + .command(({ tr }) => { + markAsClipboardEdit(tr, "paste"); + return true; + }) + // Pasted chips and lines would split shown Markdown, so parse it first. + .command(collapseShownMarkdownSource) + .insertContent(content) + .command(({ tr }) => { + // Move after a pasted rule so the next keystroke cannot replace it; add a trailing line + // if needed. + const { selection } = tr; + if (!(selection instanceof NodeSelection) || !selection.node.isBlock) { + return true; + } + if (!tr.doc.resolve(selection.to).nodeAfter?.isTextblock) { + tr.insert(selection.to, tr.doc.type.schema.nodes.paragraph!.create()); + } + tr.setSelection(TextSelection.create(tr.doc, selection.to + 1)); + return true; + }) + .run(); + }, + ); + scrollTiptapCaretIntoView(editorInstance); + } + return true; + }; + const editor = useEditor( { extensions: richText ? RICH_TEXT_EXTENSIONS : PLAIN_TEXT_EXTENSIONS, @@ -1169,6 +1264,8 @@ function ComposerPromptEditorTiptapInner( isKnownModel: (instanceId, model) => modelKeys.has(modelMentionKey(instanceId, model)), }), editable: !disabled, + // The composer parses pasted and dropped text itself; paste rules would restyle literal `*`. + enablePasteRules: false, editorProps: { attributes: editorAttributes, handleDOMEvents: { @@ -1456,100 +1553,23 @@ function ComposerPromptEditorTiptapInner( (literalText || !readPastedComposerContext(clipboardData)?.records.length) ) return false; - const pastedText = readPastedPlainText(clipboardData); - if (!pastedText) return false; + if (!insertClipboardText(view, clipboardData)) return false; event.preventDefault(); - // Paste verbatim inside fences; markdown parsing would split blocks and create unsupported chips. - if (isInCodeBlock(view)) { - const { from, to } = view.state.selection; - view.dispatch( - markAsClipboardEdit( - view.state.tr.insertText(pastedText, from, to), - "paste", - ).scrollIntoView(), - ); - return true; - } - // Shown Markdown source is parsed when the caret leaves, so paste one line into it as text. - const sourceType = view.state.schema.marks[MARKDOWN_SOURCE_MARK]; - const { from: pasteFrom, to: pasteTo, $from: $pasteFrom } = view.state.selection; - if ( - sourceType?.isInSet($pasteFrom.marks()) && - !pastedText.includes("\n") && - collectComposerPromptInlineTokens(`${pastedText}\n`).length === 0 - ) { - view.dispatch( - markAsClipboardEdit( - view.state.tr.insertText(pastedText, pasteFrom, pasteTo), - "paste", - ).scrollIntoView(), - ); - return true; - } - const importFragment = readCallbacks().importContextFragment; - let text = - !literalText && importFragment - ? importPastedComposerText(clipboardData, importFragment) - : pastedText; - const tokens = literalText ? [] : collectComposerPromptInlineTokens(`${text}\n`); - const isChip = (token: (typeof tokens)[number] | undefined) => - token?.type === "mention" || - (token?.type === "skill" && skillLabelFor(token.value) !== null) || - (token?.type === "model" && isKnownModel(token.instanceId, token.model)); - const lastToken = tokens.at(-1); - if (isChip(lastToken) && lastToken?.end === text.length) { - text += " "; - } - if (isChip(tokens[0]) && tokens[0]?.start === 0) { - const map = serializeEditorDoc(view.state.doc); - const offset = flatToMarkdown(map, pmToFlat(map, view.state.selection.from)); - if (offset > 0 && !/\s/.test(map.value[offset - 1]!)) text = ` ${text}`; - } - const { $from } = view.state.selection; - const lineBefore = $from.parent.textBetween(0, $from.parentOffset, undefined, "\uFFFC"); - const literalLength = literalText - ? 0 - : pastedPathQueryLength(lineBefore, text, readCallbacks().isPathQueryActive?.()); - const editorInstance = (view.dom as TiptapEditorHTMLElement).editor; - if (editorInstance) { - const $paste = view.state.selection.$from; - const nested = ["listItem", "taskItem", "blockquote"].some((name) => - hasAncestor($paste, name), - ); - insertMarkdownParagraphs( - text, - skillLabelFor, - { styling: richText, blocks: !nested, literalText, literalLength, isKnownModel }, - (content) => { - editorInstance - .chain() - .command(({ tr }) => { - markAsClipboardEdit(tr, "paste"); - return true; - }) - // Pasted chips and lines would split shown Markdown, so parse it first. - .command(collapseShownMarkdownSource) - .insertContent(content) - .command(({ tr }) => { - // Move after a pasted rule so the next keystroke cannot replace it; add a trailing line - // if needed. - const { selection } = tr; - if (!(selection instanceof NodeSelection) || !selection.node.isBlock) { - return true; - } - if (!tr.doc.resolve(selection.to).nodeAfter?.isTextblock) { - tr.insert(selection.to, tr.doc.type.schema.nodes.paragraph!.create()); - } - tr.setSelection(TextSelection.create(tr.doc, selection.to + 1)); - return true; - }) - .run(); - }, - ); - scrollTiptapCaretIntoView(editorInstance); - } return true; }, + handleDrop: (view, event, _slice, moved) => { + const data = event.dataTransfer; + // Files and drags that start inside the editor keep ProseMirror's own drop. + if (moved || view.dragging || !data || data.files.length > 0) return false; + const target = view.posAtCoords({ left: event.clientX, top: event.clientY }); + if (!target || !readPastedPlainText(data)) return false; + view.dispatch( + view.state.tr.setSelection(TextSelection.near(view.state.doc.resolve(target.pos))), + ); + // Handling the drop skips ProseMirror's own focus call. + view.focus(); + return insertClipboardText(view, data); + }, }, onUpdate: ({ editor: updated, transaction }) => { // Undo can restore a chip for a skill or model the environment no longer offers. From 57a1b662fbb1de1bf7d87a786881d1375a95c7ee Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:25:41 -0800 Subject: [PATCH 10/13] fix(web): text dropped between composer blocks no longer replaces one TextSelection.near could pick a horizontal rule or the end of a code fence next to the drop point, so the dropped text replaced the rule or joined the code. Only drops inside a textblock take the paste path now; ProseMirror's own drop inserts a new block between blocks. Co-Authored-By: Claude Opus 5.5 --- ...rPromptEditorTiptap.input.browser.test.tsx | 26 +++++++++++++++++++ .../components/ComposerPromptEditorTiptap.tsx | 4 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index cd80bf910fb52..c3cf7da1b9aaa 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -594,6 +594,32 @@ it.each([ expect(editor.view.hasFocus()).toBe(true); }); +it("drops text on a rule's edge without replacing the rule", async () => { + await using screen = await mountEditor("before\n\n---\n\nafter"); + const { editor } = screen; + let rulePos = -1; + editor.state.doc.forEach((node, offset) => { + if (node.type.name === "horizontalRule") rulePos = offset; + }); + const rule = (editor.view.nodeDOM(rulePos) as HTMLElement).getBoundingClientRect(); + await act(async () => { + const dataTransfer = new DataTransfer(); + dataTransfer.setData("text/plain", "dropped"); + editor.view.dom.dispatchEvent( + new DragEvent("drop", { + dataTransfer, + clientX: rule.left + rule.width / 2, + clientY: rule.top, + bubbles: true, + cancelable: true, + }), + ); + }); + const value = serializeEditorDoc(editor.state.doc).value; + expect(value).toContain("---"); + expect(value).toContain("dropped"); +}); + it.each([ ["**DEV**", "**DEV**!"], ["*DEV*", "*DEV*!"], diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index 188bdc1a58fda..c9e9bafc07c86 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -1563,8 +1563,10 @@ function ComposerPromptEditorTiptapInner( if (moved || view.dragging || !data || data.files.length > 0) return false; const target = view.posAtCoords({ left: event.clientX, top: event.clientY }); if (!target || !readPastedPlainText(data)) return false; + // Between blocks, ProseMirror's drop inserts a new block; a nearby selection would replace or join one. + if (!view.state.doc.resolve(target.pos).parent.inlineContent) return false; view.dispatch( - view.state.tr.setSelection(TextSelection.near(view.state.doc.resolve(target.pos))), + view.state.tr.setSelection(TextSelection.create(view.state.doc, target.pos)), ); // Handling the drop skips ProseMirror's own focus call. view.focus(); From 920f7baae01c3aafa8f1f9749ae89d8dd2486b5b Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:34:04 -0800 Subject: [PATCH 11/13] fix(web): markdown dropped in an empty composer's padding is parsed Chromium resolves a drop below the first line of an empty composer to the document boundary, so the drop fell back to ProseMirror's literal insert. A boundary drop next to an empty paragraph now fills it through the paste path. Co-Authored-By: Claude Opus 5.5 --- ...rPromptEditorTiptap.input.browser.test.tsx | 21 +++++++++++++++++++ .../components/ComposerPromptEditorTiptap.tsx | 17 ++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index c3cf7da1b9aaa..b2f278152d259 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -594,6 +594,27 @@ it.each([ expect(editor.view.hasFocus()).toBe(true); }); +it("parses markdown dropped below the first line of an empty composer", async () => { + await using screen = await mountEditor(""); + const { editor } = screen; + const box = editor.view.dom.getBoundingClientRect(); + await act(async () => { + const dataTransfer = new DataTransfer(); + dataTransfer.setData("text/plain", "a **bold** word"); + editor.view.dom.dispatchEvent( + new DragEvent("drop", { + dataTransfer, + clientX: box.left + 4, + clientY: box.bottom - 1, + bubbles: true, + cancelable: true, + }), + ); + }); + expect(serializeEditorDoc(editor.state.doc).value).toBe("a **bold** word"); + expect(editor.state.doc.textContent).toBe("a bold word"); +}); + it("drops text on a rule's edge without replacing the rule", async () => { await using screen = await mountEditor("before\n\n---\n\nafter"); const { editor } = screen; diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index c9e9bafc07c86..0071861e9dc7e 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -1563,11 +1563,18 @@ function ComposerPromptEditorTiptapInner( if (moved || view.dragging || !data || data.files.length > 0) return false; const target = view.posAtCoords({ left: event.clientX, top: event.clientY }); if (!target || !readPastedPlainText(data)) return false; - // Between blocks, ProseMirror's drop inserts a new block; a nearby selection would replace or join one. - if (!view.state.doc.resolve(target.pos).parent.inlineContent) return false; - view.dispatch( - view.state.tr.setSelection(TextSelection.create(view.state.doc, target.pos)), - ); + let pos = target.pos; + const $target = view.state.doc.resolve(pos); + if (!$target.parent.inlineContent) { + // Between blocks, fill an adjacent empty paragraph (the padding of an empty composer); otherwise + // ProseMirror's drop inserts a new block, where a nearby selection would replace or join one. + const isEmptyParagraph = (node: typeof $target.nodeAfter) => + node?.type.name === "paragraph" && node.content.size === 0; + if (isEmptyParagraph($target.nodeAfter)) pos += 1; + else if (isEmptyParagraph($target.nodeBefore)) pos -= 1; + else return false; + } + view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, pos))); // Handling the drop skips ProseMirror's own focus call. view.focus(); return insertClipboardText(view, data); From f0693981dfbec8484caaeeaebf5baf3d3e862e3a Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:45:33 -0800 Subject: [PATCH 12/13] fix(web): text dropped below the composer's last line is parsed A drop between blocks with no empty paragraph next to it fell back to ProseMirror's default drop, which preferred text/html (a dropped link lost its URL), collapsed blank lines, and skipped the composer's parser. The drop now starts a new line at ProseMirror's drop point inside the paste transaction, so it parses like a paste and undoes in one step. Co-Authored-By: Claude Opus 5.5 --- ...rPromptEditorTiptap.input.browser.test.tsx | 27 +++++++++++++ .../components/ComposerPromptEditorTiptap.tsx | 38 ++++++++++++++----- apps/web/src/composer-undo-grouping.ts | 5 +-- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index b2f278152d259..c90f01c53242f 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -615,6 +615,33 @@ it("parses markdown dropped below the first line of an empty composer", async () expect(editor.state.doc.textContent).toBe("a bold word"); }); +it("drops plain text on a new line below the last line", async () => { + await using screen = await mountEditor("before"); + const { editor } = screen; + const box = editor.view.dom.getBoundingClientRect(); + await act(async () => { + const dataTransfer = new DataTransfer(); + dataTransfer.setData("text/plain", "Docs https://example.com/document\n\nsecond"); + dataTransfer.setData("text/html", 'Docs'); + editor.view.dom.dispatchEvent( + new DragEvent("drop", { + dataTransfer, + clientX: box.left + 4, + clientY: box.bottom - 1, + bubbles: true, + cancelable: true, + }), + ); + }); + expect(serializeEditorDoc(editor.state.doc).value).toBe( + "before\nDocs https://example.com/document\n\nsecond", + ); + await act(async () => { + editor.commands.undo(); + }); + expect(serializeEditorDoc(editor.state.doc).value).toBe("before"); +}); + it("drops text on a rule's edge without replacing the rule", async () => { await using screen = await mountEditor("before\n\n---\n\nafter"); const { editor } = screen; diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index 0071861e9dc7e..cbdd56eb20f04 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -28,7 +28,8 @@ import { type Transaction, } from "@tiptap/pm/state"; import { Decoration, DecorationSet, type EditorView } from "@tiptap/pm/view"; -import type { NodeType, ResolvedPos } from "@tiptap/pm/model"; +import { Fragment, type NodeType, type ResolvedPos, Slice } from "@tiptap/pm/model"; +import { dropPoint } from "@tiptap/pm/transform"; import type { AssistantCitation, ComposerContextClipboardFragment, @@ -1160,11 +1161,17 @@ function ComposerPromptEditorTiptapInner( "aria-placeholder": placeholder, }; - const insertClipboardText = (view: EditorView, clipboardData: DataTransfer): boolean => { + /** `newLineAt` inserts on a fresh line created at that block boundary, in the same undo step. */ + const insertClipboardText = ( + view: EditorView, + clipboardData: DataTransfer, + newLineAt?: number, + ): boolean => { const pastedText = readPastedPlainText(clipboardData); if (!pastedText) return false; + const onNewLine = newLineAt !== undefined; // Paste verbatim inside fences; markdown parsing would split blocks and create unsupported chips. - if (isInCodeBlock(view)) { + if (!onNewLine && isInCodeBlock(view)) { const { from, to } = view.state.selection; view.dispatch( markAsClipboardEdit( @@ -1178,6 +1185,7 @@ function ComposerPromptEditorTiptapInner( const sourceType = view.state.schema.marks[MARKDOWN_SOURCE_MARK]; const { from: pasteFrom, to: pasteTo, $from: $pasteFrom } = view.state.selection; if ( + !onNewLine && sourceType?.isInSet($pasteFrom.marks()) && !pastedText.includes("\n") && collectComposerPromptInlineTokens(`${pastedText}\n`).length === 0 @@ -1204,19 +1212,21 @@ function ComposerPromptEditorTiptapInner( if (isChip(lastToken) && lastToken?.end === text.length) { text += " "; } - if (isChip(tokens[0]) && tokens[0]?.start === 0) { + if (!onNewLine && isChip(tokens[0]) && tokens[0]?.start === 0) { const map = serializeEditorDoc(view.state.doc); const offset = flatToMarkdown(map, pmToFlat(map, view.state.selection.from)); if (offset > 0 && !/\s/.test(map.value[offset - 1]!)) text = ` ${text}`; } const { $from } = view.state.selection; - const lineBefore = $from.parent.textBetween(0, $from.parentOffset, undefined, "\uFFFC"); + const lineBefore = onNewLine + ? "" + : $from.parent.textBetween(0, $from.parentOffset, undefined, "\uFFFC"); const literalLength = literalText ? 0 : pastedPathQueryLength(lineBefore, text, readCallbacks().isPathQueryActive?.()); const editorInstance = (view.dom as TiptapEditorHTMLElement).editor; if (editorInstance) { - const $paste = view.state.selection.$from; + const $paste = onNewLine ? view.state.doc.resolve(newLineAt) : view.state.selection.$from; const nested = ["listItem", "taskItem", "blockquote"].some((name) => hasAncestor($paste, name), ); @@ -1229,6 +1239,10 @@ function ComposerPromptEditorTiptapInner( .chain() .command(({ tr }) => { markAsClipboardEdit(tr, "paste"); + if (onNewLine) { + tr.insert(newLineAt, tr.doc.type.schema.nodes.paragraph!.create()); + tr.setSelection(TextSelection.create(tr.doc, newLineAt + 1)); + } return true; }) // Pasted chips and lines would split shown Markdown, so parse it first. @@ -1566,13 +1580,19 @@ function ComposerPromptEditorTiptapInner( let pos = target.pos; const $target = view.state.doc.resolve(pos); if (!$target.parent.inlineContent) { - // Between blocks, fill an adjacent empty paragraph (the padding of an empty composer); otherwise - // ProseMirror's drop inserts a new block, where a nearby selection would replace or join one. + // Between blocks, fill an adjacent empty paragraph (the padding of an empty composer) or start + // a new line; a nearby selection would replace or join a block. const isEmptyParagraph = (node: typeof $target.nodeAfter) => node?.type.name === "paragraph" && node.content.size === 0; if (isEmptyParagraph($target.nodeAfter)) pos += 1; else if (isEmptyParagraph($target.nodeBefore)) pos -= 1; - else return false; + else { + const line = view.state.schema.nodes.paragraph!.create(); + const at = dropPoint(view.state.doc, pos, new Slice(Fragment.from(line), 0, 0)); + if (at === null) return false; + view.focus(); + return insertClipboardText(view, data, at); + } } view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, pos))); // Handling the drop skips ProseMirror's own focus call. diff --git a/apps/web/src/composer-undo-grouping.ts b/apps/web/src/composer-undo-grouping.ts index 2a7a5a94028e7..5d33ee4c62762 100644 --- a/apps/web/src/composer-undo-grouping.ts +++ b/apps/web/src/composer-undo-grouping.ts @@ -10,10 +10,7 @@ export type ComposerChangeKind = "insert" | "delete" | "other"; const CLIPBOARD_EDIT_META = "composerClipboardEdit"; const COMPOSITION_REPLACE_META = "composerCompositionReplace"; -/** - * Tag custom paste/cut dispatches; ProseMirror only tags its built-in paths. - * Not `uiEvent`: Tiptap's paste rules would style the already parsed paste a second time. - */ +/** Tag custom paste/cut dispatches; ProseMirror only tags its built-in paths. */ export function markAsClipboardEdit(tr: Transaction, event: "paste" | "cut"): Transaction { return tr.setMeta(CLIPBOARD_EDIT_META, event); } From c10002297cb147f914e99d739a031c434665dc6d Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:54:11 -0800 Subject: [PATCH 13/13] fix(web): text dropped on a list marker stays in the list dropPoint could not fit a bare paragraph between list items, so it walked up and placed the dropped text outside the whole list. A new line is now only started where a paragraph fits at the drop position; elsewhere ProseMirror's drop adds a list item as before. Co-Authored-By: Claude Opus 5.5 --- ...rPromptEditorTiptap.input.browser.test.tsx | 20 +++++++++++++++++++ .../components/ComposerPromptEditorTiptap.tsx | 14 ++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index c90f01c53242f..5047c88556353 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -642,6 +642,26 @@ it("drops plain text on a new line below the last line", async () => { expect(serializeEditorDoc(editor.state.doc).value).toBe("before"); }); +it("drops text on a list marker inside the list", async () => { + await using screen = await mountEditor("- one\n- two"); + const { editor } = screen; + const item = editor.view.dom.querySelectorAll("li")[1]!.getBoundingClientRect(); + await act(async () => { + const dataTransfer = new DataTransfer(); + dataTransfer.setData("text/plain", "added"); + editor.view.dom.dispatchEvent( + new DragEvent("drop", { + dataTransfer, + clientX: item.left - 8, + clientY: item.top + item.height / 2, + bubbles: true, + cancelable: true, + }), + ); + }); + expect(serializeEditorDoc(editor.state.doc).value).toMatch(/^- one\n.*added[\s\S]*- two$/); +}); + it("drops text on a rule's edge without replacing the rule", async () => { await using screen = await mountEditor("before\n\n---\n\nafter"); const { editor } = screen; diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx index cbdd56eb20f04..1088e27f2a05d 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx @@ -28,8 +28,7 @@ import { type Transaction, } from "@tiptap/pm/state"; import { Decoration, DecorationSet, type EditorView } from "@tiptap/pm/view"; -import { Fragment, type NodeType, type ResolvedPos, Slice } from "@tiptap/pm/model"; -import { dropPoint } from "@tiptap/pm/transform"; +import type { NodeType, ResolvedPos } from "@tiptap/pm/model"; import type { AssistantCitation, ComposerContextClipboardFragment, @@ -1581,17 +1580,18 @@ function ComposerPromptEditorTiptapInner( const $target = view.state.doc.resolve(pos); if (!$target.parent.inlineContent) { // Between blocks, fill an adjacent empty paragraph (the padding of an empty composer) or start - // a new line; a nearby selection would replace or join a block. + // a new line at the drop point; a nearby selection would replace or join a block. const isEmptyParagraph = (node: typeof $target.nodeAfter) => node?.type.name === "paragraph" && node.content.size === 0; if (isEmptyParagraph($target.nodeAfter)) pos += 1; else if (isEmptyParagraph($target.nodeBefore)) pos -= 1; else { - const line = view.state.schema.nodes.paragraph!.create(); - const at = dropPoint(view.state.doc, pos, new Slice(Fragment.from(line), 0, 0)); - if (at === null) return false; + const index = $target.index(); + const paragraph = view.state.schema.nodes.paragraph!; + // Between list items a paragraph does not fit; ProseMirror's drop adds an item there. + if (!$target.parent.canReplaceWith(index, index, paragraph)) return false; view.focus(); - return insertClipboardText(view, data, at); + return insertClipboardText(view, data, pos); } } view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, pos)));