mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-23 15:32:59 +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:
committed by
Ian Storm Taylor
parent
1d53c5b1ef
commit
dc95ad66a5
@@ -204,12 +204,9 @@ function AfterPlugin() {
|
|||||||
function onCut(event, change, editor) {
|
function onCut(event, change, editor) {
|
||||||
debug('onCut', { event })
|
debug('onCut', { event })
|
||||||
|
|
||||||
cloneFragment(event, change.value)
|
|
||||||
const window = getWindow(event.target)
|
|
||||||
|
|
||||||
// Once the fake cut content has successfully been added to the clipboard,
|
// Once the fake cut content has successfully been added to the clipboard,
|
||||||
// delete the content in the current selection.
|
// 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,
|
// If user cuts a void block node or a void inline node,
|
||||||
// manually removes it since selection is collapsed in this case.
|
// manually removes it since selection is collapsed in this case.
|
||||||
const { value } = change
|
const { value } = change
|
||||||
|
@@ -18,7 +18,12 @@ const { FRAGMENT, HTML, TEXT } = TRANSFER_TYPES
|
|||||||
* @param {Document} [fragment]
|
* @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 window = getWindow(event.target)
|
||||||
const native = window.getSelection()
|
const native = window.getSelection()
|
||||||
const { start, end } = value.selection
|
const { start, end } = value.selection
|
||||||
@@ -106,7 +111,7 @@ function cloneFragment(event, value, fragment = value.fragment) {
|
|||||||
event.clipboardData.setData(TEXT, plainText)
|
event.clipboardData.setData(TEXT, plainText)
|
||||||
event.clipboardData.setData(FRAGMENT, encoded)
|
event.clipboardData.setData(FRAGMENT, encoded)
|
||||||
event.clipboardData.setData(HTML, div.innerHTML)
|
event.clipboardData.setData(HTML, div.innerHTML)
|
||||||
return
|
callback()
|
||||||
}
|
}
|
||||||
|
|
||||||
// COMPAT: For browser that don't support the Clipboard API's setData method,
|
// 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)
|
editor.removeChild(div)
|
||||||
removeAllRanges(native)
|
removeAllRanges(native)
|
||||||
native.addRange(range)
|
native.addRange(range)
|
||||||
|
callback()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user