diff --git a/.changeset/pretty-plums-grow.md b/.changeset/pretty-plums-grow.md
new file mode 100644
index 000000000..bce1b086b
--- /dev/null
+++ b/.changeset/pretty-plums-grow.md
@@ -0,0 +1,5 @@
+---
+'slate': patch
+---
+
+Fix for insertFragment text/inline + block mixed fragments.
diff --git a/packages/slate/src/transforms/text.ts b/packages/slate/src/transforms/text.ts
index c127b8566..c64e61fd1 100644
--- a/packages/slate/src/transforms/text.ts
+++ b/packages/slate/src/transforms/text.ts
@@ -397,7 +397,7 @@ export const TextTransforms: TextTransforms = {
const middleRef = Editor.pathRef(
editor,
- isBlockEnd ? Path.next(blockPath) : blockPath
+ isBlockEnd && !ends.length ? Path.next(blockPath) : blockPath
)
const endRef = Editor.pathRef(
@@ -405,8 +405,6 @@ export const TextTransforms: TextTransforms = {
isInlineEnd ? Path.next(inlinePath) : inlinePath
)
- const blockPathRef = Editor.pathRef(editor, blockPath)
-
Transforms.splitNodes(editor, {
at,
match: n =>
@@ -414,6 +412,10 @@ export const TextTransforms: TextTransforms = {
? Editor.isBlock(editor, n)
: Text.isText(n) || Editor.isInline(editor, n),
mode: hasBlocks ? 'lowest' : 'highest',
+ always:
+ hasBlocks &&
+ (!isBlockStart || starts.length > 0) &&
+ (!isBlockEnd || ends.length > 0),
voids,
})
@@ -431,8 +433,8 @@ export const TextTransforms: TextTransforms = {
voids,
})
- if (isBlockEmpty && middles.length) {
- Transforms.delete(editor, { at: blockPathRef.unref()!, voids })
+ if (isBlockEmpty && !starts.length && middles.length && !ends.length) {
+ Transforms.delete(editor, { at: blockPath, voids })
}
Transforms.insertNodes(editor, middles, {
diff --git a/packages/slate/test/transforms/insertFragment/of-mixed/block-empty.tsx b/packages/slate/test/transforms/insertFragment/of-mixed/block-empty.tsx
new file mode 100644
index 000000000..06ac456e5
--- /dev/null
+++ b/packages/slate/test/transforms/insertFragment/of-mixed/block-empty.tsx
@@ -0,0 +1,33 @@
+/** @jsx jsx */
+import { Transforms } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Transforms.insertFragment(
+ editor,
+
+ one
+ two
+ three
+
+ )
+}
+export const input = (
+
+ word
+
+
+
+
+)
+export const output = (
+
+ word
+ one
+ two
+
+ three
+
+
+
+)
diff --git a/packages/slate/test/transforms/insertFragment/of-mixed/block-empty2.tsx b/packages/slate/test/transforms/insertFragment/of-mixed/block-empty2.tsx
new file mode 100644
index 000000000..acd981042
--- /dev/null
+++ b/packages/slate/test/transforms/insertFragment/of-mixed/block-empty2.tsx
@@ -0,0 +1,33 @@
+/** @jsx jsx */
+import { Transforms } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Transforms.insertFragment(
+ editor,
+
+ two
+ three
+
+ )
+}
+export const input = (
+
+ word
+
+
+
+
+)
+export const output = (
+
+ word
+ two
+
+
+ three
+
+
+
+
+)
diff --git a/packages/slate/test/transforms/insertFragment/of-mixed/block-empty3.tsx b/packages/slate/test/transforms/insertFragment/of-mixed/block-empty3.tsx
new file mode 100644
index 000000000..5cbf9af38
--- /dev/null
+++ b/packages/slate/test/transforms/insertFragment/of-mixed/block-empty3.tsx
@@ -0,0 +1,31 @@
+/** @jsx jsx */
+import { Transforms } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Transforms.insertFragment(
+ editor,
+
+ one
+ two
+
+ )
+}
+export const input = (
+
+ word
+
+
+
+
+)
+export const output = (
+
+ word
+ one
+
+ two
+
+
+
+)
diff --git a/packages/slate/test/transforms/insertFragment/of-mixed/block-end.tsx b/packages/slate/test/transforms/insertFragment/of-mixed/block-end.tsx
new file mode 100644
index 000000000..5e71575ac
--- /dev/null
+++ b/packages/slate/test/transforms/insertFragment/of-mixed/block-end.tsx
@@ -0,0 +1,32 @@
+/** @jsx jsx */
+import { Transforms } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Transforms.insertFragment(
+ editor,
+
+ one
+ two
+ three
+
+ )
+}
+export const input = (
+
+
+ word
+
+
+
+)
+export const output = (
+
+ wordone
+ two
+
+ three
+
+
+
+)
diff --git a/packages/slate/test/transforms/insertFragment/of-mixed/block-end2.tsx b/packages/slate/test/transforms/insertFragment/of-mixed/block-end2.tsx
new file mode 100644
index 000000000..c289cb5c6
--- /dev/null
+++ b/packages/slate/test/transforms/insertFragment/of-mixed/block-end2.tsx
@@ -0,0 +1,30 @@
+/** @jsx jsx */
+import { Transforms } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Transforms.insertFragment(
+ editor,
+
+ one
+ two
+
+ )
+}
+export const input = (
+
+
+ word
+
+
+
+)
+export const output = (
+
+ wordone
+
+ two
+
+
+
+)
diff --git a/packages/slate/test/transforms/insertFragment/of-mixed/block-middle.tsx b/packages/slate/test/transforms/insertFragment/of-mixed/block-middle.tsx
new file mode 100644
index 000000000..c6a689243
--- /dev/null
+++ b/packages/slate/test/transforms/insertFragment/of-mixed/block-middle.tsx
@@ -0,0 +1,34 @@
+/** @jsx jsx */
+import { Transforms } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Transforms.insertFragment(
+ editor,
+
+ one
+ two
+ three
+
+ )
+}
+export const input = (
+
+
+ wo
+
+ rd
+
+
+)
+export const output = (
+
+ woone
+ two
+
+ three
+
+ rd
+
+
+)
diff --git a/packages/slate/test/transforms/insertFragment/of-mixed/block-start.tsx b/packages/slate/test/transforms/insertFragment/of-mixed/block-start.tsx
new file mode 100644
index 000000000..a173aa5b5
--- /dev/null
+++ b/packages/slate/test/transforms/insertFragment/of-mixed/block-start.tsx
@@ -0,0 +1,33 @@
+/** @jsx jsx */
+import { Transforms } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Transforms.insertFragment(
+ editor,
+
+ one
+ two
+ three
+
+ )
+}
+export const input = (
+
+
+
+ word
+
+
+)
+export const output = (
+
+ one
+ two
+
+ three
+
+ word
+
+
+)
diff --git a/packages/slate/test/transforms/insertFragment/of-mixed/block-start2.tsx b/packages/slate/test/transforms/insertFragment/of-mixed/block-start2.tsx
new file mode 100644
index 000000000..209a6f8d8
--- /dev/null
+++ b/packages/slate/test/transforms/insertFragment/of-mixed/block-start2.tsx
@@ -0,0 +1,31 @@
+/** @jsx jsx */
+import { Transforms } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Transforms.insertFragment(
+ editor,
+
+ one
+ two
+
+ )
+}
+export const input = (
+
+
+
+ word
+
+
+)
+export const output = (
+
+ one
+
+ two
+
+ word
+
+
+)