Merge f3fb5050475e5879e2a31cc52ff0b3d340a371ed into 1b0f2e5463cf56d47bfbfc44b7752f5f1784b4fa
This commit is contained in:
commit
4118cb3ada
@ -286,7 +286,14 @@ export const createAbsolutePositionFromRelativePosition = (rpos, doc, followUndo
|
|||||||
if (getState(store, rightID.client) <= rightID.clock) {
|
if (getState(store, rightID.client) <= rightID.clock) {
|
||||||
return null
|
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
|
const right = res.item
|
||||||
if (!(right instanceof Item)) {
|
if (!(right instanceof Item)) {
|
||||||
return null
|
return null
|
||||||
|
@ -123,3 +123,17 @@ export const testRelativePositionWithUndo = tc => {
|
|||||||
t.assert(Y.createAbsolutePositionFromRelativePosition(rpos, ydocClone)?.index === 6)
|
t.assert(Y.createAbsolutePositionFromRelativePosition(rpos, ydocClone)?.index === 6)
|
||||||
t.assert(Y.createAbsolutePositionFromRelativePosition(rpos, ydocClone, false)?.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)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user