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

fix insert fragment with void children (#2624)

This commit is contained in:
Yoel
2019-03-06 14:41:39 -07:00
committed by Ian Storm Taylor
parent 9dc53c5d82
commit 2740907b7f
2 changed files with 43 additions and 1 deletions

View File

@@ -789,7 +789,11 @@ Commands.insertFragmentAtRange = (editor, range, fragment) => {
// If the starting block is empty, we replace it entirely with the first block // If the starting block is empty, we replace it entirely with the first block
// of the fragment, since this leads to a more expected behavior for the user. // of the fragment, since this leads to a more expected behavior for the user.
if (!editor.isVoid(startBlock) && startBlock.text === '') { if (
!editor.isVoid(startBlock) &&
startBlock.text === '' &&
!startBlock.findDescendant(n => editor.isVoid(n))
) {
editor.removeNodeByKey(startBlock.key) editor.removeNodeByKey(startBlock.key)
editor.insertNodeByKey(parent.key, index, firstBlock) editor.insertNodeByKey(parent.key, index, firstBlock)
} else { } else {

View File

@@ -0,0 +1,38 @@
/** @jsx h */
import h from '../../../helpers/h'
export default function(editor) {
editor.insertFragment(
<document>
<paragraph>
<text>one</text>
<text>two</text>
</paragraph>
</document>
)
}
export const input = (
<value>
<document>
<paragraph>
<emoji />
<cursor />
</paragraph>
</document>
</value>
)
export const output = (
<value>
<document>
<paragraph>
<emoji />
<text>
onetwo<cursor />
</text>
</paragraph>
</document>
</value>
)