From dbdd49af23edbe63b5983787e70e5b31fa382518 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Tue, 7 Nov 2017 20:10:01 -0800 Subject: [PATCH] fix relativePosition if startof is a root type --- src/Type/YMap.js | 8 +++++++- src/Util/relativePosition.js | 13 ++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Type/YMap.js b/src/Type/YMap.js index 9c162bfa..7a621135 100644 --- a/src/Type/YMap.js +++ b/src/Type/YMap.js @@ -36,7 +36,13 @@ export default class YMap extends Type { return map } keys () { - return Array.from(this._map.keys()).filter(x => !x._deleted) + let keys = [] + for (let [key, value] of this._map) { + if (!value._deleted) { + keys.push(key) + } + } + return keys } delete (key) { this._transact((y) => { diff --git a/src/Util/relativePosition.js b/src/Util/relativePosition.js index b5788065..423274d5 100644 --- a/src/Util/relativePosition.js +++ b/src/Util/relativePosition.js @@ -1,8 +1,9 @@ -import ID from './ID' +import ID from './ID.js' +import RootID from './RootID.js' export function getRelativePosition (type, offset) { if (offset === 0) { - return ['startof', type._id.user, type._id.clock] + return ['startof', type._id.user, type._id.clock || null, type._id.type || null] } else { let t = type._start while (t !== null) { @@ -23,8 +24,14 @@ export function getRelativePosition (type, offset) { export function fromRelativePosition (y, rpos) { if (rpos[0] === 'startof') { + let id + if (rpos[3] === null) { + id = new ID(rpos[1], rpos[2]) + } else { + id = new RootID(rpos[1], rpos[3]) + } return { - type: y.os.get(new ID(rpos[1], rpos[2])), + type: y.os.get(id), offset: 0 } } else {