mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-23 15:32:59 +02:00
Fix normalize range of the insertTextAtRange (#1659)
This commit is contained in:
committed by
Ian Storm Taylor
parent
4422f8afca
commit
28220e7007
@@ -851,8 +851,19 @@ Changes.insertTextAtRange = (change, range, text, marks, options = {}) => {
|
|||||||
if (normalize !== undefined) {
|
if (normalize !== undefined) {
|
||||||
normalize = range.isExpanded
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user