Skip to content

Commit c4556ab

Browse files
authored
fix(web): stop wrapping partial code block selections in markdown fences (#5069)
1 parent f075a58 commit c4556ab

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

apps/web/src/markdown-clipboard.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,17 @@ export function chatMarkdownClipboardPayload(
301301
if (range.collapsed) continue;
302302
const container = document.createElement("div");
303303
container.appendChild(range.cloneContents());
304+
const ancestor = range.commonAncestorContainer;
305+
const ancestorElement =
306+
ancestor.nodeType === Node.ELEMENT_NODE ? (ancestor as Element) : ancestor.parentElement;
307+
if (ancestorElement?.closest("pre")) {
308+
const text = range.toString();
309+
if (text) {
310+
texts.push(text);
311+
htmls.push(sanitizedHtmlFrom(container));
312+
}
313+
continue;
314+
}
304315
const text = serializeRenderedMarkdownFragment(container);
305316
if (!text) continue;
306317
texts.push(text);

0 commit comments

Comments
 (0)