Compare commits

...

1 Commits

Author SHA1 Message Date
Ara 4a865cac45 Revert "fix: Resolve all different copy paste issues once and for all (#3443)"
This reverts commit 26eafd96dd.
2025-05-16 02:20:33 +05:30
+9 -54
View File
@@ -146,62 +146,17 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
if (window.getSelection) {
const selection = window.getSelection()
if (selection && selection.rangeCount > 0) {
// Get the selected HTML content
const range = selection.getRangeAt(0)
const commonAncestor = range.commonAncestorContainer
let textToCopy: string | null = null
const clonedSelection = range.cloneContents()
const div = document.createElement("div")
div.appendChild(clonedSelection)
const selectedHtml = div.innerHTML
// Check if the selection is inside an element where plain text copy is preferred
let currentElement =
commonAncestor.nodeType === Node.ELEMENT_NODE
? (commonAncestor as HTMLElement)
: commonAncestor.parentElement
let preferPlainTextCopy = false
while (currentElement) {
if (currentElement.tagName === "PRE" && currentElement.querySelector("code")) {
preferPlainTextCopy = true
break
}
// Check computed white-space style
const computedStyle = window.getComputedStyle(currentElement)
if (
computedStyle.whiteSpace === "pre" ||
computedStyle.whiteSpace === "pre-wrap" ||
computedStyle.whiteSpace === "pre-line"
) {
// If the element itself or an ancestor has pre-like white-space,
// and the selection is likely contained within it, prefer plain text.
// This helps with elements like the TaskHeader's text display.
preferPlainTextCopy = true
break
}
// Stop searching if we reach a known chat message boundary or body
if (
currentElement.classList.contains("chat-row-assistant-message-container") ||
currentElement.classList.contains("chat-row-user-message-container") ||
currentElement.tagName === "BODY"
) {
break
}
currentElement = currentElement.parentElement
}
if (preferPlainTextCopy) {
// For code blocks or elements with pre-formatted white-space, get plain text.
textToCopy = selection.toString()
} else {
// For other content, use the existing HTML-to-Markdown conversion
const clonedSelection = range.cloneContents()
const div = document.createElement("div")
div.appendChild(clonedSelection)
const selectedHtml = div.innerHTML
textToCopy = await convertHtmlToMarkdown(selectedHtml)
}
if (textToCopy !== null) {
vscode.postMessage({ type: "copyToClipboard", text: textToCopy })
e.preventDefault()
}
// Convert HTML to Markdown
const markdown = await convertHtmlToMarkdown(selectedHtml)
vscode.postMessage({ type: "copyToClipboard", text: markdown })
e.preventDefault()
}
}
}