From 1ce7c7cc8937dba80c6b75f154a6e3dab2855aa5 Mon Sep 17 00:00:00 2001 From: phy <13335561+pjshy@users.noreply.github.com> Date: Wed, 30 Jan 2019 08:09:18 +0800 Subject: [PATCH] fix(at-range): correct `findInsertionNode` method throw a type error when there arg is a Text node (#2498) --- packages/slate/src/commands/at-range.js | 6 ++- .../fragment-single-child-block.js | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 packages/slate/test/commands/at-current-range/insert-fragment/fragment-single-child-block.js diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 37a46a752..6e0290f03 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -808,7 +808,11 @@ Commands.insertFragmentAtRange = (editor, range, fragment) => { } const findInsertionNode = (fragment, document, startKey) => { - const hasSingleNode = object => object && object.nodes.size === 1 + const hasSingleNode = object => { + if (!object || object.object === 'text') return + return object.nodes.size === 1 + } + const firstNode = object => object && object.nodes.first() let node = fragment diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/fragment-single-child-block.js b/packages/slate/test/commands/at-current-range/insert-fragment/fragment-single-child-block.js new file mode 100644 index 000000000..c5f57ae90 --- /dev/null +++ b/packages/slate/test/commands/at-current-range/insert-fragment/fragment-single-child-block.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + 2 + + + ) +} + +export const input = ( + + + + + 1 + + + + +) + +export const output = ( + + + + + 12 + + + + +)