diff --git a/src/structs/ContentFormat.js b/src/structs/ContentFormat.js index 4b82bba7..6ac4c29c 100644 --- a/src/structs/ContentFormat.js +++ b/src/structs/ContentFormat.js @@ -100,4 +100,4 @@ export class ContentFormat { * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {ContentFormat} */ -export const readContentFormat = decoder => new ContentFormat(decoder.readString(), decoder.readJSON()) +export const readContentFormat = decoder => new ContentFormat(decoder.readKey(), decoder.readJSON()) diff --git a/src/utils/UpdateEncoder.js b/src/utils/UpdateEncoder.js index a7c301d3..e8c5d06c 100644 --- a/src/utils/UpdateEncoder.js +++ b/src/utils/UpdateEncoder.js @@ -298,10 +298,24 @@ export class UpdateEncoderV2 extends DSEncoderV2 { writeKey (key) { const clock = this.keyMap.get(key) if (clock === undefined) { + /** + * @todo uncomment to introduce this feature finally + * + * Background. The ContentFormat object was always encoded using writeKey, but the decoder used to use readString. + * Furthermore, I forgot to set the keyclock. So everything was working fine. + * + * However, this feature here is basically useless as it is not being used (it actually only consumes extra memory). + * + * I don't know yet how to reintroduce this feature.. + * + * Older clients won't be able to read updates when we reintroduce this feature. So this should probably be done using a flag. + * + */ + // this.keyMap.set(key, this.keyClock) this.keyClockEncoder.write(this.keyClock++) this.stringEncoder.write(key) } else { - this.keyClockEncoder.write(this.keyClock++) + this.keyClockEncoder.write(clock) } } } diff --git a/tests/updates.tests.js b/tests/updates.tests.js index 9ae50440..dce09e71 100644 --- a/tests/updates.tests.js +++ b/tests/updates.tests.js @@ -112,6 +112,24 @@ export const testMergeUpdates = tc => { }) } +/** + * @param {t.TestCase} tc + */ +export const testKeyEncoding = tc => { + const { users, text0, text1 } = init(tc, { users: 2 }) + + text0.insert(0, 'a', { italic: true }) + text0.insert(0, 'b') + text0.insert(0, 'c', { italic: true }) + + const update = Y.encodeStateAsUpdateV2(users[0]) + Y.applyUpdateV2(users[1], update) + + t.compare(text1.toDelta(), [{ insert: 'c', attributes: { italic: true } }, { insert: 'b' }, { insert: 'a', attributes: { italic: true } }]) + + compare(users) +} + /** * @param {Y.Doc} ydoc * @param {Array} updates - expecting at least 4 updates