mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-18 21:21:21 +02:00
Delete single void node when cutting (#1336)
* fix deletion on cut void nodes * detect isCollapsed on paste * update comment
This commit is contained in:
committed by
Ian Storm Taylor
parent
bb7e30c5fb
commit
c397d0cdd7
@@ -122,7 +122,20 @@ function AfterPlugin() {
|
|||||||
// 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(() => {
|
window.requestAnimationFrame(() => {
|
||||||
|
// 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
|
||||||
|
const { endBlock, endInline, isCollapsed } = value
|
||||||
|
const isVoidBlock = endBlock && endBlock.isVoid && isCollapsed
|
||||||
|
const isVoidInline = endInline && endInline.isVoid && isCollapsed
|
||||||
|
|
||||||
|
if (isVoidBlock) {
|
||||||
|
editor.change(c => c.removeNodeByKey(endBlock.key))
|
||||||
|
} else if (isVoidInline) {
|
||||||
|
editor.change(c => c.removeNodeByKey(endInline.key))
|
||||||
|
} else {
|
||||||
editor.change(c => c.delete())
|
editor.change(c => c.delete())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user