fix #657 - relative positions issue when using followUndoneDeletions=false

This commit is contained in:
Kevin Jahns
2024-12-21 00:52:48 +01:00
parent 1b0f2e5463
commit f583d2a211
2 changed files with 34 additions and 2 deletions

View File

@@ -9,7 +9,7 @@ import {
ContentType,
followRedone,
getItem,
ID, Doc, AbstractType // eslint-disable-line
StructStore, ID, Doc, AbstractType, // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding'
@@ -256,6 +256,18 @@ export const readRelativePosition = decoder => {
*/
export const decodeRelativePosition = uint8Array => readRelativePosition(decoding.createDecoder(uint8Array))
/**
* @param {StructStore} store
* @param {ID} id
*/
const getItemWithOffset = (store, id) => {
const item = getItem(store, id)
const diff = id.clock - item.id.clock
return {
item, diff
}
}
/**
* Transform a relative position to an absolute position.
*
@@ -286,7 +298,7 @@ export const createAbsolutePositionFromRelativePosition = (rpos, doc, followUndo
if (getState(store, rightID.client) <= rightID.clock) {
return null
}
const res = followUndoneDeletions ? followRedone(store, rightID) : { item: getItem(store, rightID), diff: 0 }
const res = followUndoneDeletions ? followRedone(store, rightID) : getItemWithOffset(store, rightID)
const right = res.item
if (!(right instanceof Item)) {
return null