mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 22:21:20 +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:
5
.changeset/shy-planets-eat.md
Normal file
5
.changeset/shy-planets-eat.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
unwrapNode call liftNode in reverse order to keep nested block
|
@@ -848,7 +848,13 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
|
|
||||||
const rangeRef = Range.isRange(at) ? Editor.rangeRef(editor, at) : null
|
const rangeRef = Range.isRange(at) ? Editor.rangeRef(editor, at) : null
|
||||||
const matches = Editor.nodes(editor, { at, match, mode, voids })
|
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) {
|
for (const pathRef of pathRefs) {
|
||||||
const path = pathRef.unref()!
|
const path = pathRef.unref()!
|
||||||
|
@@ -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>
|
||||||
|
)
|
Reference in New Issue
Block a user