mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 14:41:23 +02:00
Attach the cloned DOM node before coputing its plaintext representation when copying. (#3543)
The cloned dom node constructed when copying must be attached to the dom for getComputedStyle to work. This adds the div to the body as a hidden element and removes after computing its text representation.
This commit is contained in:
@@ -1087,13 +1087,18 @@ const setFragmentData = (
|
|||||||
// Add the content to a <div> so that we can get its inner HTML.
|
// Add the content to a <div> so that we can get its inner HTML.
|
||||||
const div = document.createElement('div')
|
const div = document.createElement('div')
|
||||||
div.appendChild(contents)
|
div.appendChild(contents)
|
||||||
|
div.setAttribute('hidden', 'true')
|
||||||
|
document.body.appendChild(div)
|
||||||
dataTransfer.setData('text/html', div.innerHTML)
|
dataTransfer.setData('text/html', div.innerHTML)
|
||||||
dataTransfer.setData('text/plain', getPlainText(div))
|
dataTransfer.setData('text/plain', getPlainText(div))
|
||||||
|
document.body.removeChild(div)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a plaintext representation of the content of a node, accounting for block
|
* Get a plaintext representation of the content of a node, accounting for block
|
||||||
* elements which get a newline appended.
|
* elements which get a newline appended.
|
||||||
|
*
|
||||||
|
* The domNode must be attached to the DOM.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const getPlainText = (domNode: DOMNode) => {
|
const getPlainText = (domNode: DOMNode) => {
|
||||||
|
Reference in New Issue
Block a user