mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-27 00:54:22 +02:00
add target
property to split_node operations (#1138)
This commit is contained in:
@@ -442,7 +442,7 @@ Changes.setNodeByKey = (change, key, properties, options = {}) => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Changes.splitNodeByKey = (change, key, position, options = {}) => {
|
Changes.splitNodeByKey = (change, key, position, options = {}) => {
|
||||||
const { normalize = true } = options
|
const { normalize = true, target = null } = options
|
||||||
const { state } = change
|
const { state } = change
|
||||||
const { document } = state
|
const { document } = state
|
||||||
const path = document.getPath(key)
|
const path = document.getPath(key)
|
||||||
@@ -451,6 +451,7 @@ Changes.splitNodeByKey = (change, key, position, options = {}) => {
|
|||||||
type: 'split_node',
|
type: 'split_node',
|
||||||
path,
|
path,
|
||||||
position,
|
position,
|
||||||
|
target,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
@@ -483,11 +484,13 @@ Changes.splitDescendantsByKey = (change, key, textKey, textOffset, options = {})
|
|||||||
const ancestors = document.getAncestors(textKey)
|
const ancestors = document.getAncestors(textKey)
|
||||||
const nodes = ancestors.skipUntil(a => a.key == key).reverse().unshift(text)
|
const nodes = ancestors.skipUntil(a => a.key == key).reverse().unshift(text)
|
||||||
let previous
|
let previous
|
||||||
|
let index
|
||||||
|
|
||||||
nodes.forEach((node) => {
|
nodes.forEach((node) => {
|
||||||
const index = previous ? node.nodes.indexOf(previous) + 1 : textOffset
|
const prevIndex = index == null ? null : index
|
||||||
|
index = previous ? node.nodes.indexOf(previous) + 1 : textOffset
|
||||||
previous = node
|
previous = node
|
||||||
change.splitNodeByKey(node.key, index, { normalize: false })
|
change.splitNodeByKey(node.key, index, { normalize: false, target: prevIndex })
|
||||||
})
|
})
|
||||||
|
|
||||||
if (normalize) {
|
if (normalize) {
|
||||||
|
Reference in New Issue
Block a user