From 2740907b7fd57cbc6a0fd27aba8b61002242369f Mon Sep 17 00:00:00 2001 From: Yoel Date: Wed, 6 Mar 2019 14:41:39 -0700 Subject: [PATCH] fix insert fragment with void children (#2624) --- packages/slate/src/commands/at-range.js | 6 ++- .../start-block-with-void-no-text.js | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 packages/slate/test/commands/at-current-range/insert-fragment/start-block-with-void-no-text.js diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 6e0290f03..4a0308002 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -789,7 +789,11 @@ Commands.insertFragmentAtRange = (editor, range, fragment) => { // 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. - if (!editor.isVoid(startBlock) && startBlock.text === '') { + if ( + !editor.isVoid(startBlock) && + startBlock.text === '' && + !startBlock.findDescendant(n => editor.isVoid(n)) + ) { editor.removeNodeByKey(startBlock.key) editor.insertNodeByKey(parent.key, index, firstBlock) } else { diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/start-block-with-void-no-text.js b/packages/slate/test/commands/at-current-range/insert-fragment/start-block-with-void-no-text.js new file mode 100644 index 000000000..b1efcd24c --- /dev/null +++ b/packages/slate/test/commands/at-current-range/insert-fragment/start-block-with-void-no-text.js @@ -0,0 +1,38 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + + + ) +} + +export const input = ( + + + + + + + + +) + +export const output = ( + + + + + + onetwo + + + + +)