diff --git a/packages/slate/src/commands/with-intent.js b/packages/slate/src/commands/with-intent.js
index 977a101de..911e11f77 100644
--- a/packages/slate/src/commands/with-intent.js
+++ b/packages/slate/src/commands/with-intent.js
@@ -278,7 +278,19 @@ Commands.insertFragment = (editor, fragment) => {
if (newText && (lastInline || isInserting)) {
editor.moveToEndOfNode(newText)
} else if (newText) {
- editor.moveToStartOfNode(newText).moveForward(lastBlock.text.length)
+ // The position within the last text node needs to be calculated. This is the length
+ // of all text nodes within the last block, but if the last block contains inline nodes,
+ // these have to be skipped.
+ const { nodes } = lastBlock
+ const lastIndex = nodes.findLastIndex(
+ node => node && node.object === 'inline'
+ )
+ const remainingTexts = nodes.takeLast(nodes.size - lastIndex - 1)
+ const remainingTextLength = remainingTexts.reduce(
+ (acc, val) => acc + val.text.length,
+ 0
+ )
+ editor.moveToStartOfNode(newText).moveForward(remainingTextLength)
}
}
diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/fragment-inline-node.js b/packages/slate/test/commands/at-current-range/insert-fragment/fragment-inline-node.js
new file mode 100644
index 000000000..49652f5d1
--- /dev/null
+++ b/packages/slate/test/commands/at-current-range/insert-fragment/fragment-inline-node.js
@@ -0,0 +1,35 @@
+/** @jsx h */
+
+import h from '../../../helpers/h'
+
+export default function(editor) {
+ editor.insertFragment(
+
+
+ one
+ Some inline stuff
+ two
+
+
+ )
+}
+
+export const input = (
+
+
+
+ AB
+
+
+
+)
+
+export const output = (
+
+
+
+ AoneSome inline stufftwoB
+
+
+
+)