mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 17:53:59 +02:00
fix: mergeNodes by point would delete nested multi-child node (#3825)
This commit is contained in:
@@ -381,8 +381,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
const emptyAncestor = Editor.above(editor, {
|
const emptyAncestor = Editor.above(editor, {
|
||||||
at: path,
|
at: path,
|
||||||
mode: 'highest',
|
mode: 'highest',
|
||||||
match: n =>
|
match: n => levels.includes(n) && hasSingleChildNest(editor, n),
|
||||||
levels.includes(n) && Element.isElement(n) && n.children.length === 1,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const emptyRef = emptyAncestor && Editor.pathRef(editor, emptyAncestor[1])
|
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.
|
* 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>
|
||||||
|
)
|
Reference in New Issue
Block a user