Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f30c784

Browse files
committed
fix attribution change event to contain explicit attributions
1 parent 2b5af46 commit f30c784

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
},
7272
"homepage": "https://docs.yjs.dev",
7373
"dependencies": {
74-
"lib0": "^1.0.0-rc.7"
74+
"lib0": "^1.0.0-rc.12"
7575
},
7676
"devDependencies": {
7777
"@types/node": "^22.14.1",

src/utils/ids.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,13 @@ export const iterateStructsByIdSetWithoutSplits = (store, ds, f) =>
378378
const ranges = idRanges.getIds()
379379
const structs = /** @type {Array<GC|Item>} */ (store.clients.get(clientid))
380380
if (structs != null) {
381+
const lastStruct = structs[structs.length - 1]
382+
const nextClock = lastStruct.id.clock + lastStruct.length
381383
for (let i = 0; i < ranges.length; i++) {
382384
const del = ranges[i]
383-
iterateStructsWithoutSplits(structs, del.clock, del.len, f)
385+
if (del.clock < nextClock) {
386+
iterateStructsWithoutSplits(structs, del.clock, del.len, f)
387+
}
384388
}
385389
}
386390
})

tests/attribution.tests.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,22 @@ export const testAttributionEvent = () => {
195195
ytype.delete(0, 1)
196196
t.assert(called)
197197
}
198+
199+
export const testAttributionChange = () => {
200+
const ydoc = new Y.Doc()
201+
const ytype = ydoc.get()
202+
ytype.applyDelta(delta.create().insert('hi').done())
203+
const ydocClone = Y.cloneDoc(ydoc)
204+
const am = Y.createAttributionManagerFromDiff(ydocClone, ydoc)
205+
ytype.applyDelta(delta.create().retain(2).insert('!').done())
206+
let calledHandler = false
207+
am.on('change', changes => {
208+
calledHandler = true
209+
const changeUpdate = ytype.toDelta(am, { deep: true, itemsToRender: changes, retainInserts: true, retainDeletes: true })
210+
const expectedUpdate = delta.create().retain(2).retain(1, null, {})
211+
t.compare(changeUpdate, expectedUpdate)
212+
console.log(changeUpdate.toJSON())
213+
})
214+
Y.applyUpdate(ydocClone, Y.encodeStateAsUpdate(ydoc))
215+
t.assert(calledHandler)
216+
}

0 commit comments

Comments
 (0)