Merge f3fb5050475e5879e2a31cc52ff0b3d340a371ed into 1b0f2e5463cf56d47bfbfc44b7752f5f1784b4fa

This commit is contained in:
Juan Martín Seery 2024-12-20 11:07:25 +01:00 committed by GitHub
commit 4118cb3ada
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View File

@ -286,7 +286,14 @@ 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 }
/** @type {ReturnType<typeof followRedone>} */
let res;
if (followUndoneDeletions) {
res = followRedone(store, rightID)
} else {
const item = getItem(store, rightID)
res = { item, diff: rightID.clock - item.id.clock }
}
const right = res.item
if (!(right instanceof Item)) {
return null

View File

@ -123,3 +123,17 @@ export const testRelativePositionWithUndo = tc => {
t.assert(Y.createAbsolutePositionFromRelativePosition(rpos, ydocClone)?.index === 6)
t.assert(Y.createAbsolutePositionFromRelativePosition(rpos, ydocClone, false)?.index === 6)
}
/**
* @param {t.TestCase} tc
*/
export const testRelativePositionWithoutUndo = tc => {
const ydoc = new Y.Doc()
const ytext = ydoc.getText()
ytext.insert(0, 'abcde')
const rpos = Y.createRelativePositionFromTypeIndex(ytext, 2)
const posWithFollow = Y.createAbsolutePositionFromRelativePosition(rpos, ydoc, true)
t.assert(posWithFollow?.index === 2)
const posWithoutFollow = Y.createAbsolutePositionFromRelativePosition(rpos, ydoc, false)
t.assert(posWithoutFollow?.index === 2)
}