1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-27 09:04:31 +02:00

add target property to split_node operations (#1138)

This commit is contained in:
Ian Storm Taylor
2017-09-18 15:12:57 -07:00
committed by GitHub
parent 56bbf57623
commit cb93e9f5c3

View File

@@ -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) {