From 47bcf6e609ee347d896f749b9fd0911a68b4cb1b Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Mon, 23 Nov 2026 16:14:59 +0100 Subject: [PATCH] fix(app): keep a partial callout selection free of its marker A selection that started inside an admonition's body kept the box as its wrapper, so the copy added `> [!TYPE]` the user never selected. The callout marker is now restored only when the copied markup includes the generated title, which a whole callout or quote copy always does. Co-authored-by: Pedro Vieira Co-authored-by: Phieu Dinh --- .../content.browser.test.ts | 15 +++++++++++++++ .../src/assistant-selection-copy/content.web.ts | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/app/src/assistant-selection-copy/content.browser.test.ts b/packages/app/src/assistant-selection-copy/content.browser.test.ts index 2c39c5a134..70d15aec28 100644 --- a/packages/app/src/assistant-selection-copy/content.browser.test.ts +++ b/packages/app/src/assistant-selection-copy/content.browser.test.ts @@ -1087,6 +1087,21 @@ describe("quote copy", () => { expect(content?.plainText).toBe("Before\n\n> [!WARNING]\n> Do not deploy.\n\nAfter"); }); + it("copies a selection that starts inside an admonition without its callout marker", async () => { + const rendered = await renderMarkdown( + "> Before\n>\n> > [!WARNING]\n> > Do not deploy.\n>\n> After", + "After", + ); + rendered.setAttribute("data-testid", "assistant-message"); + + const content = copyBetween( + [tokenText(rendered, "Do not deploy."), "Do not ".length], + [tokenText(rendered, "After"), "After".length], + ); + + expect(content?.plainText).toBe("deploy.\n\nAfter"); + }); + it("copies a rendered Mermaid diagram as its fence", () => { const quote = document.createElement("blockquote"); quote.innerHTML = `

Before

After

`; diff --git a/packages/app/src/assistant-selection-copy/content.web.ts b/packages/app/src/assistant-selection-copy/content.web.ts index 8bc01833e3..492b850431 100644 --- a/packages/app/src/assistant-selection-copy/content.web.ts +++ b/packages/app/src/assistant-selection-copy/content.web.ts @@ -757,13 +757,16 @@ function numberOrderedListItems(list: Element, start: number): void { /** * The library renders an admonition as a box with a generated title. Keep it a quote * with its type, so it copies as its callout source rather than as the title's prose. + * A selection that starts inside the body has no title and copies as prose. */ function restoreAdmonitions(container: HTMLElement): void { const admonitions = Array.from( container.querySelectorAll(`[${MARKDOWN_ADMONITION_TYPE_ATTRIBUTE}]`), ); for (const admonition of admonitions.toReversed()) { - admonition.querySelector(`:scope > [${MARKDOWN_ADMONITION_TITLE_ATTRIBUTE}]`)?.remove(); + const title = admonition.querySelector(`:scope > [${MARKDOWN_ADMONITION_TITLE_ATTRIBUTE}]`); + if (!title) continue; + title.remove(); const quote = document.createElement("blockquote"); quote.setAttribute( MARKDOWN_ADMONITION_TYPE_ATTRIBUTE,