mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-24 01:02:31 +01:00
fix: mergeNodes by point would delete nested multi-child node (#3825)
This commit is contained in:
parent
9fce1066ba
commit
aafee36834
@ -381,8 +381,7 @@ export const NodeTransforms: NodeTransforms = {
|
||||
const emptyAncestor = Editor.above(editor, {
|
||||
at: path,
|
||||
mode: 'highest',
|
||||
match: n =>
|
||||
levels.includes(n) && Element.isElement(n) && n.children.length === 1,
|
||||
match: n => levels.includes(n) && hasSingleChildNest(editor, n),
|
||||
})
|
||||
|
||||
const emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1])
|
||||
@ -963,6 +962,23 @@ export const NodeTransforms: NodeTransforms = {
|
||||
},
|
||||
}
|
||||
|
||||
const hasSingleChildNest = (editor: Editor, node: Node): boolean => {
|
||||
if (Element.isElement(node)) {
|
||||
const element = node as Element
|
||||
if (Editor.isVoid(editor, node)) {
|
||||
return true
|
||||
} else if (element.children.length === 1) {
|
||||
return hasSingleChildNest(editor, element.children[0])
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
} else if (Editor.isEditor(node)) {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a range into a point by deleting it's content.
|
||||
*/
|
||||
|
@ -0,0 +1,63 @@
|
||||
/** @jsx jsx */
|
||||
import { jsx } from '../../..'
|
||||
import { Transforms } from 'slate'
|
||||
|
||||
export const run = editor => {
|
||||
Transforms.mergeNodes(editor, {
|
||||
at: {
|
||||
path: [0, 1, 1, 0, 0, 0],
|
||||
offset: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
<block>
|
||||
<text>123</text>
|
||||
</block>
|
||||
<block>
|
||||
<block>
|
||||
<text>45</text>
|
||||
</block>
|
||||
<block>
|
||||
<block>
|
||||
<block>
|
||||
<text>c</text>
|
||||
</block>
|
||||
<block>
|
||||
<block>
|
||||
<text>edf</text>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>
|
||||
<block>
|
||||
<text>123</text>
|
||||
</block>
|
||||
<block>
|
||||
<block>
|
||||
<text>45c</text>
|
||||
</block>
|
||||
<block>
|
||||
<block>
|
||||
<block>
|
||||
<block>
|
||||
<text>edf</text>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
@ -0,0 +1,49 @@
|
||||
/** @jsx jsx */
|
||||
import { jsx } from '../../..'
|
||||
import { Transforms } from 'slate'
|
||||
|
||||
export const run = editor => {
|
||||
Transforms.mergeNodes(editor, {
|
||||
at: {
|
||||
path: [0, 1, 1, 0, 0, 0],
|
||||
offset: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
<block>
|
||||
<text>123</text>
|
||||
</block>
|
||||
<block>
|
||||
<block>
|
||||
<text>45</text>
|
||||
</block>
|
||||
<block>
|
||||
<block>
|
||||
<block>
|
||||
<text>c</text>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<editor>
|
||||
<block>
|
||||
<block>
|
||||
<text>123</text>
|
||||
</block>
|
||||
<block>
|
||||
<block>
|
||||
<text>45c</text>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user