1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 23:12:52 +02:00

Fix normalize range of the insertTextAtRange (#1659)

This commit is contained in:
Jinxuan Zhu
2018-03-23 13:53:54 -04:00
committed by Ian Storm Taylor
parent 4422f8afca
commit 28220e7007

View File

@@ -851,8 +851,19 @@ Changes.insertTextAtRange = (change, range, text, marks, options = {}) => {
if (normalize !== undefined) {
normalize = range.isExpanded
}
change.insertTextByKey(key, offset, text, marks, { normalize: false })
change.insertTextByKey(key, offset, text, marks, { normalize })
if (normalize) {
// normalize in the narrowest existing block that originally contains startKey and endKey
const commonAncestor = document.getCommonAncestor(startKey, range.endKey)
const ancestors = document
.getAncestors(commonAncestor.key)
.push(commonAncestor)
const normalizeAncestor = ancestors.findLast(n =>
change.value.document.getDescendant(n.key)
)
change.normalizeNodeByKey(normalizeAncestor.key)
}
}
/**