fix: deleteText currPos left and right both null

Handle the case where both `currPos.left` and `currPos.right` are null in `YText::deleteText` to prevent error `Cannot read properties of null (reading 'parent')` .

Fixes https://github.com/yjs/yjs/issues/504.
This commit is contained in:
Rich Evans 2023-02-23 12:44:20 -08:00 committed by GitHub
parent 658c520b93
commit 34d70afadf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -498,8 +498,8 @@ const deleteText = (transaction, currPos, length) => {
if (start) {
cleanupFormattingGap(transaction, start, currPos.right, startAttrs, currPos.currentAttributes)
}
const parent = /** @type {AbstractType<any>} */ (/** @type {Item} */ (currPos.left || currPos.right).parent)
if (parent._searchMarker) {
const parent = /** @type {AbstractType<any>} */ (/** @type {Item} */ (currPos.left || currPos.right)?.parent)
if (parent?._searchMarker) {
updateMarkerChanges(parent._searchMarker, currPos.index, -startLength + length)
}
return currPos