fix(app): keep selection copy of a callout as the text it shows

A selection clone cannot tell a whole callout from part of one, so
restoring `> [!TYPE]` there dropped a partly selected title and added the
marker to a partial body. Only whole-quote copy restores the callout now;
selection copy keeps its earlier behavior.

Co-authored-by: Pedro Vieira <pedro.vieira@dremio.com>
Co-authored-by: Phieu Dinh <phieu@fiu.one>
This commit is contained in:
Mohamed Boudra
2026-11-23 16:26:14 +01:00
co-authored by Pedro Vieira Phieu Dinh
parent 47bcf6e609
commit a796e760e9
3 changed files with 18 additions and 15 deletions
+1 -1
View File
@@ -45,7 +45,7 @@ Mermaid fences use the existing isolated diagram runtime and fullscreen viewer.
Code blocks and plain quotes have a copy control in their top trailing corner. Native code blocks use the library's compiled grammars. On native, the code block and quote container views share one control (`HeaderCopyButton` on Android, `ENRMHeaderCopyButton` on iOS). A quote reserves the code block's header band above its body, so the control never covers quote text at any font size. On web, code blocks use `HighlightedCodeBlock` through the library's `renderers.codeBlock` override, and quotes use `WebBlockquote` through `renderers.blockquote`. Both use `BlockCopyButton`. On compact layouts the control is always visible, so the web quote reserves a band above its body, as native does. On wide layouts the control appears on hover or focus, so the quote keeps a right gutter instead; a band there would leave an empty strip above every quote.
A quote copies its body without the `>` markers, with its nested Markdown, and reads the content at the time of the press, so a streaming quote copies what it shows. A nested quote or code block keeps its own control. Web quote copy uses the same two clipboard flavors as selection copy: `text/plain` is unescaped Markdown and `text/html` is rendered from escaped Markdown. A rendered Mermaid diagram copies as its fence because its wrapper carries the fence source. Native quote copy serializes the quote's parsed Markdown, so a workspace image copies as its cached file URL, as native selection copy does; native has no map back to the workspace path. A native Mermaid diagram in a quote renders outside it (see [native selection limitations](native-text-selection.md)), so each quote fragment copies only its own text. Admonitions get no control: web renders them with a separate library renderer. On web an admonition inside a copied quote or selection copies as its `> [!TYPE]` source; the fork marks the box and its generated title for this. On native, quotes inside list items get no control, because they render as text spans in the item. Web renders them as blocks, so they get one.
A quote copies its body without the `>` markers, with its nested Markdown, and reads the content at the time of the press, so a streaming quote copies what it shows. A nested quote or code block keeps its own control. Web quote copy uses the same two clipboard flavors as selection copy: `text/plain` is unescaped Markdown and `text/html` is rendered from escaped Markdown. A rendered Mermaid diagram copies as its fence because its wrapper carries the fence source. Native quote copy serializes the quote's parsed Markdown, so a workspace image copies as its cached file URL, as native selection copy does; native has no map back to the workspace path. A native Mermaid diagram in a quote renders outside it (see [native selection limitations](native-text-selection.md)), so each quote fragment copies only its own text. Admonitions get no control: web renders them with a separate library renderer. On web an admonition inside a copied quote copies as its `> [!TYPE]` source; the fork marks the box and its generated title for this. Selection copy keeps the text it shows, because the cloned range cannot tell a whole callout from part of one. On native, quotes inside list items get no control, because they render as text spans in the item. Web renders them as blocks, so they get one.
Selection copy has to tell links Paseo recognized in the text (paths, forge references, code spans) from links in the Markdown, so the web link renderer marks the recognized ones. Plain-text paste carries them as the text the reply showed, and rich paste keeps them as links only when they point to an `http` or `https` URL. Authored links and parser autolinks such as a bare `www.example.com` copy as links. The fork also keeps the library's block spacing around the web code block override, preserves web list numbering and link titles, marks pending parses with `aria-busy` so Find waits for rendered text, and carries link syntax through native and web tap events. Web inline code inside a link inherits only the link colour; its code font, size and background stay intact. Keep link variants colour-only: native pills replace text runs and prevent paths from wrapping; Android pills also use the surrounding block’s font size. [Upstream PR #997](https://github.com/software-mansion/enriched-markdown/pull/997) tracks these changes.
@@ -1087,19 +1087,24 @@ 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 () => {
it("copies a selection across an admonition as the text it shows, without a 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 body = tokenText(rendered, "Do not deploy.");
const content = copyBetween(
[tokenText(rendered, "Do not deploy."), "Do not ".length],
[tokenText(rendered, "After"), "After".length],
);
expect(content?.plainText).toBe("deploy.\n\nAfter");
expect(
copyBetween([body, "Do not ".length], [tokenText(rendered, "After"), 5])?.plainText,
).toBe("deploy.\n\nAfter");
expect(
copyBetween([tokenText(rendered, "Before"), 0], [tokenText(rendered, "Warning"), 4])
?.plainText,
).toBe("Before\n\nWarn");
expect(
copyBetween([tokenText(rendered, "Before"), 0], [body, "Do not".length])?.plainText,
).not.toContain("[!WARNING]");
});
it("copies a rendered Mermaid diagram as its fence", () => {
@@ -163,6 +163,7 @@ export function createElementClipboardContent(element: Element): MarkdownClipboa
const copies = container.querySelectorAll("*");
originals.forEach((original, index) => copySemanticAttributes(original, copies[index]!));
restoreFenceSources(container);
restoreAdmonitions(container);
restoreMarkdownElements(container);
return clipboardContentFromMarkup(container);
}
@@ -730,8 +731,6 @@ function restoreMarkdownElements(container: HTMLElement): void {
element.replaceWith(...element.childNodes);
}
restoreAdmonitions(container);
const presentational = Array.from(container.querySelectorAll("div, span"));
for (const element of presentational.toReversed()) {
element.replaceWith(...element.childNodes);
@@ -757,16 +756,15 @@ 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.
* Only a whole-element copy does this: a selection cannot tell from its cloned markup
* whether it holds the whole callout, so it copies the text it shows.
*/
function restoreAdmonitions(container: HTMLElement): void {
function restoreAdmonitions(container: Element): void {
const admonitions = Array.from(
container.querySelectorAll(`[${MARKDOWN_ADMONITION_TYPE_ATTRIBUTE}]`),
);
for (const admonition of admonitions.toReversed()) {
const title = admonition.querySelector(`:scope > [${MARKDOWN_ADMONITION_TITLE_ATTRIBUTE}]`);
if (!title) continue;
title.remove();
admonition.querySelector(`:scope > [${MARKDOWN_ADMONITION_TITLE_ATTRIBUTE}]`)?.remove();
const quote = document.createElement("blockquote");
quote.setAttribute(
MARKDOWN_ADMONITION_TYPE_ATTRIBUTE,