fixed selection handler befor/after transactions
This commit is contained in:
@@ -4,14 +4,20 @@ export function getRelativePosition (type, offset) {
|
||||
if (offset === 0) {
|
||||
return ['startof', type._id.user, type._id.clock]
|
||||
} else {
|
||||
let t = type.start
|
||||
while (t !== null && t.length < offset) {
|
||||
let t = type._start
|
||||
while (t !== null) {
|
||||
if (t._length >= offset) {
|
||||
return [t._id.user, t._id.clock + offset - 1]
|
||||
}
|
||||
if (t._right === null) {
|
||||
return [t._id.user, t._id.clock + t._length - 1]
|
||||
}
|
||||
if (!t._deleted) {
|
||||
offset -= t.length
|
||||
offset -= t._length
|
||||
}
|
||||
t = t._right
|
||||
}
|
||||
return [t._id.user, t._id.clock + offset - 1]
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,19 +29,20 @@ export function fromRelativePosition (y, rpos) {
|
||||
}
|
||||
} else {
|
||||
let offset = 0
|
||||
let struct = y.os.findNodeWithUpperBound(new ID(rpos[0], rpos[1]))
|
||||
let parent = struct._parent
|
||||
let struct = y.os.findNodeWithUpperBound(new ID(rpos[0], rpos[1])).val
|
||||
const parent = struct._parent
|
||||
if (parent._deleted) {
|
||||
return null
|
||||
}
|
||||
if (!struct.deleted) {
|
||||
offset = rpos[1] - struct._id.clock
|
||||
if (!struct._deleted) {
|
||||
offset = rpos[1] - struct._id.clock + 1
|
||||
}
|
||||
while (struct.left !== null) {
|
||||
struct = struct.left
|
||||
if (!struct.deleted) {
|
||||
struct = struct._left
|
||||
while (struct !== null) {
|
||||
if (!struct._deleted) {
|
||||
offset += struct._length
|
||||
}
|
||||
struct = struct._left
|
||||
}
|
||||
return {
|
||||
type: parent,
|
||||
|
||||
Reference in New Issue
Block a user