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

Do not use requestAnimation if DataTransfer is available (#2052)

*  not to requestAnimationFrame in modern browser

* Fix bugs

* Fix bugs

* Fix bugs

* Use callback
This commit is contained in:
Jinxuan Zhu
2018-08-10 13:40:14 -04:00
committed by Ian Storm Taylor
parent 1d53c5b1ef
commit dc95ad66a5
2 changed files with 9 additions and 6 deletions

View File

@@ -204,12 +204,9 @@ function AfterPlugin() {
function onCut(event, change, editor) {
debug('onCut', { event })
cloneFragment(event, change.value)
const window = getWindow(event.target)
// Once the fake cut content has successfully been added to the clipboard,
// delete the content in the current selection.
window.requestAnimationFrame(() => {
cloneFragment(event, change.value, change.value.fragment, () => {
// If user cuts a void block node or a void inline node,
// manually removes it since selection is collapsed in this case.
const { value } = change

View File

@@ -18,7 +18,12 @@ const { FRAGMENT, HTML, TEXT } = TRANSFER_TYPES
* @param {Document} [fragment]
*/
function cloneFragment(event, value, fragment = value.fragment) {
function cloneFragment(
event,
value,
fragment = value.fragment,
callback = () => undefined
) {
const window = getWindow(event.target)
const native = window.getSelection()
const { start, end } = value.selection
@@ -106,7 +111,7 @@ function cloneFragment(event, value, fragment = value.fragment) {
event.clipboardData.setData(TEXT, plainText)
event.clipboardData.setData(FRAGMENT, encoded)
event.clipboardData.setData(HTML, div.innerHTML)
return
callback()
}
// COMPAT: For browser that don't support the Clipboard API's setData method,
@@ -124,6 +129,7 @@ function cloneFragment(event, value, fragment = value.fragment) {
editor.removeChild(div)
removeAllRanges(native)
native.addRange(range)
callback()
})
}