diff --git a/packages/slate/src/interfaces/editor/transforms/node.ts b/packages/slate/src/interfaces/editor/transforms/node.ts
index 078e42d64..f025b5e83 100644
--- a/packages/slate/src/interfaces/editor/transforms/node.ts
+++ b/packages/slate/src/interfaces/editor/transforms/node.ts
@@ -681,13 +681,8 @@ export const NodeTransforms = {
}
) {
Editor.withoutNormalizing(editor, () => {
- const {
- at = editor.selection,
- mode = 'highest',
- split = false,
- voids = false,
- } = options
- let { match } = options
+ const { mode = 'highest', split = false, voids = false } = options
+ let { at = editor.selection, match } = options
if (!at) {
return
@@ -697,6 +692,11 @@ export const NodeTransforms = {
match = Path.isPath(at) ? matchPath(editor, at) : 'block'
}
+ if (Path.isPath(at)) {
+ at = Editor.range(editor, at)
+ }
+
+ const rangeRef = Range.isRange(at) ? Editor.rangeRef(editor, at) : null
const matches = Editor.nodes(editor, { at, match, mode, voids })
const pathRefs = Array.from(matches, ([, p]) => Editor.pathRef(editor, p))
@@ -705,8 +705,8 @@ export const NodeTransforms = {
const [node] = Editor.node(editor, path)
let range = Editor.range(editor, path)
- if (split && Range.isRange(at)) {
- range = Range.intersection(at, range)!
+ if (split && rangeRef) {
+ range = Range.intersection(rangeRef.current!, range)!
}
Editor.liftNodes(editor, {
@@ -715,6 +715,10 @@ export const NodeTransforms = {
voids,
})
}
+
+ if (rangeRef) {
+ rangeRef.unref()
+ }
})
},
diff --git a/packages/slate/test/transforms/unwrapNodes/mode-all/match-ancestors.js b/packages/slate/test/transforms/unwrapNodes/mode-all/match-ancestors.js
new file mode 100644
index 000000000..0225d5efa
--- /dev/null
+++ b/packages/slate/test/transforms/unwrapNodes/mode-all/match-ancestors.js
@@ -0,0 +1,30 @@
+/** @jsx jsx */
+
+import { Editor } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all' })
+}
+
+export const input = (
+
+
+
+
+
+ word
+
+
+
+
+)
+
+export const output = (
+
+
+
+ word
+
+
+)
diff --git a/packages/slate/test/transforms/unwrapNodes/mode-all/match-siblings-and-parent.js b/packages/slate/test/transforms/unwrapNodes/mode-all/match-siblings-and-parent.js
new file mode 100644
index 000000000..d2f1c216b
--- /dev/null
+++ b/packages/slate/test/transforms/unwrapNodes/mode-all/match-siblings-and-parent.js
@@ -0,0 +1,40 @@
+/** @jsx jsx */
+
+import { Editor } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all' })
+}
+
+export const input = (
+
+
+
+
+
+ one
+
+
+
+
+ two
+
+
+
+
+
+)
+
+export const output = (
+
+
+
+ one
+
+
+ two
+
+
+
+)
diff --git a/packages/slate/test/transforms/unwrapNodes/mode-all/match-siblings.js b/packages/slate/test/transforms/unwrapNodes/mode-all/match-siblings.js
new file mode 100644
index 000000000..064a58f5a
--- /dev/null
+++ b/packages/slate/test/transforms/unwrapNodes/mode-all/match-siblings.js
@@ -0,0 +1,38 @@
+/** @jsx jsx */
+
+import { Editor } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all' })
+}
+
+export const input = (
+
+
+
+
+ one
+
+
+
+
+ two
+
+
+
+
+)
+
+export const output = (
+
+
+
+ one
+
+
+ two
+
+
+
+)
diff --git a/packages/slate/test/transforms/unwrapNodes/mode-all/match-some-siblings-and-parent-split.js b/packages/slate/test/transforms/unwrapNodes/mode-all/match-some-siblings-and-parent-split.js
new file mode 100644
index 000000000..a17704059
--- /dev/null
+++ b/packages/slate/test/transforms/unwrapNodes/mode-all/match-some-siblings-and-parent-split.js
@@ -0,0 +1,48 @@
+/** @jsx jsx */
+
+import { Editor } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all', split: true })
+}
+
+export const input = (
+
+
+
+
+
+ one
+
+
+
+
+ two
+
+
+
+
+ three
+
+
+
+)
+
+export const output = (
+
+
+
+ one
+
+
+ two
+
+
+
+
+ three
+
+
+
+)
diff --git a/packages/slate/test/transforms/unwrapNodes/mode-all/match-some-siblings-and-parent.js b/packages/slate/test/transforms/unwrapNodes/mode-all/match-some-siblings-and-parent.js
new file mode 100644
index 000000000..ed484e3e7
--- /dev/null
+++ b/packages/slate/test/transforms/unwrapNodes/mode-all/match-some-siblings-and-parent.js
@@ -0,0 +1,46 @@
+/** @jsx jsx */
+
+import { Editor } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all' })
+}
+
+export const input = (
+
+
+
+
+
+ one
+
+
+
+
+ two
+
+
+
+
+ three
+
+
+
+)
+
+export const output = (
+
+
+
+ one
+
+
+ two
+
+
+
+ three
+
+
+)
diff --git a/packages/slate/test/transforms/unwrapNodes/mode-all/match-some-siblings.js b/packages/slate/test/transforms/unwrapNodes/mode-all/match-some-siblings.js
new file mode 100644
index 000000000..b5c60ad75
--- /dev/null
+++ b/packages/slate/test/transforms/unwrapNodes/mode-all/match-some-siblings.js
@@ -0,0 +1,44 @@
+/** @jsx jsx */
+
+import { Editor } from 'slate'
+import { jsx } from '../../..'
+
+export const run = editor => {
+ Editor.unwrapNodes(editor, { match: { a: true }, mode: 'all' })
+}
+
+export const input = (
+
+
+
+
+ one
+
+
+
+
+ two
+
+
+
+
+ three
+
+
+)
+
+export const output = (
+
+
+
+ one
+
+
+ two
+
+
+
+ three
+
+
+)