fix relativePosition if startof is a root type

This commit is contained in:
Kevin Jahns 2017-11-07 20:10:01 -08:00
parent b7c05ba133
commit dbdd49af23
2 changed files with 17 additions and 4 deletions

View File

@ -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) => {

View File

@ -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 {