1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-25 00:06:30 +02:00

Append copied fragment to editor DOM node instead of page body (#1533)

* append fragment to editor DOM node instead of body

* remove semicolon
This commit is contained in:
Jenna Nichols
2018-01-16 19:46:22 -08:00
committed by Zach Schneider
parent 62ffb4681b
commit bc7acefff2

View File

@@ -92,7 +92,7 @@ function cloneFragment(event, value, fragment = value.fragment) {
attach.setAttribute('data-slate-fragment', encoded) attach.setAttribute('data-slate-fragment', encoded)
// Add the phony content to the DOM, and select it, so it will be copied. // Add the phony content to the DOM, and select it, so it will be copied.
const body = window.document.querySelector('body') const editor = window.document.querySelector('[data-slate-editor]')
const div = window.document.createElement('div') const div = window.document.createElement('div')
div.setAttribute('contenteditable', true) div.setAttribute('contenteditable', true)
div.style.position = 'absolute' div.style.position = 'absolute'
@@ -107,7 +107,7 @@ function cloneFragment(event, value, fragment = value.fragment) {
div.style.top = `${window.pageYOffset || window.document.documentElement.scrollTop}px` div.style.top = `${window.pageYOffset || window.document.documentElement.scrollTop}px`
div.appendChild(contents) div.appendChild(contents)
body.appendChild(div) editor.appendChild(div)
// COMPAT: In Firefox, trying to use the terser `native.selectAllChildren` // COMPAT: In Firefox, trying to use the terser `native.selectAllChildren`
// throws an error, so we use the older `range` equivalent. (2016/06/21) // throws an error, so we use the older `range` equivalent. (2016/06/21)
@@ -118,7 +118,7 @@ function cloneFragment(event, value, fragment = value.fragment) {
// Revert to the previous selection right after copying. // Revert to the previous selection right after copying.
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
body.removeChild(div) editor.removeChild(div)
native.removeAllRanges() native.removeAllRanges()
native.addRange(range) native.addRange(range)
}) })