1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-19 21:51:51 +02:00

fix unwrapNode when split && add in nested block (#3820)

* fix unwrapNode when splite && add in nested block

* Update packages/slate/src/transforms/node.ts

chore: add comment

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>

* chore: prettier fix

* chore: add changeset

* Update packages/slate/src/transforms/node.ts

chore: update comments

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
This commit is contained in:
Githoniel
2021-08-12 22:04:14 +08:00
committed by GitHub
parent 906e5af1b1
commit c6203a2d68
3 changed files with 55 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
'slate': minor
---
unwrapNode call liftNode in reverse order to keep nested block

View File

@@ -848,7 +848,13 @@ export const NodeTransforms: NodeTransforms = {
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))
const pathRefs = Array.from(
matches,
([, p]) => Editor.pathRef(editor, p)
// unwrapNode will call liftNode which does not support splitting the node when nested.
// If we do not reverse the order and call it from top to the bottom, it will remove all blocks
// that wrap target node. So we reverse the order.
).reverse()
for (const pathRef of pathRefs) {
const path = pathRef.unref()!

View File

@@ -0,0 +1,43 @@
/** @jsx jsx */
import { jsx } from '../../..'
import { Transforms } from 'slate'
export const run = editor => {
Transforms.unwrapNodes(editor, {
match: n => !!n.a,
mode: 'all',
split: true,
})
}
export const input = (
<editor>
<block a>
<block a>
<block>one</block>
<block>
<cursor />
word
</block>
<block>now</block>
</block>
</block>
</editor>
)
export const output = (
<editor>
<block a>
<block a>
<block>one</block>
</block>
</block>
<block>
<cursor />
word
</block>
<block a>
<block a>
<block>now</block>
</block>
</block>
</editor>
)