fixed some old todos, fixed some cases related to "content is an array"
This commit is contained in:
parent
20321c8a7d
commit
a7f845f553
@ -359,8 +359,10 @@ module.exports = function (Y /* :any */) {
|
|||||||
// increase SS
|
// increase SS
|
||||||
yield* transaction.updateState(op.id[0])
|
yield* transaction.updateState(op.id[0])
|
||||||
|
|
||||||
|
var opLen = op.content != null ? op.content.length : 1
|
||||||
|
for (var i = 0; i < opLen; i++) {
|
||||||
// notify whenOperation listeners (by id)
|
// notify whenOperation listeners (by id)
|
||||||
var sid = JSON.stringify(op.id)
|
var sid = JSON.stringify([op.id[0], op.id[1] + i])
|
||||||
var l = this.listenersById[sid]
|
var l = this.listenersById[sid]
|
||||||
delete this.listenersById[sid]
|
delete this.listenersById[sid]
|
||||||
|
|
||||||
@ -372,6 +374,7 @@ module.exports = function (Y /* :any */) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
var t = this.initializedTypes[JSON.stringify(op.parent)]
|
var t = this.initializedTypes[JSON.stringify(op.parent)]
|
||||||
|
|
||||||
// if parent is deleted, mark as gc'd and return
|
// if parent is deleted, mark as gc'd and return
|
||||||
@ -391,8 +394,9 @@ module.exports = function (Y /* :any */) {
|
|||||||
if (!op.deleted) {
|
if (!op.deleted) {
|
||||||
// Delete if DS says this is actually deleted
|
// Delete if DS says this is actually deleted
|
||||||
var len = op.content != null ? op.content.length : 1
|
var len = op.content != null ? op.content.length : 1
|
||||||
|
var startId = op.id // You must not use op.id in the following loop, because op will change when deleted
|
||||||
for (var i = 0; i < len; i++) {
|
for (var i = 0; i < len; i++) {
|
||||||
var id = [op.id[0], op.id[1] + i]
|
var id = [startId[0], startId[1] + i]
|
||||||
var opIsDeleted = yield* transaction.isDeleted(id)
|
var opIsDeleted = yield* transaction.isDeleted(id)
|
||||||
if (opIsDeleted) {
|
if (opIsDeleted) {
|
||||||
var delop = {
|
var delop = {
|
||||||
|
@ -362,25 +362,40 @@ module.exports = function (Y/* :any */) {
|
|||||||
n.id[1] + n.len >= next.id[1]
|
n.id[1] + n.len >= next.id[1]
|
||||||
) {
|
) {
|
||||||
diff = n.id[1] + n.len - next.id[1] // from next.start to n.end
|
diff = n.id[1] + n.len - next.id[1] // from next.start to n.end
|
||||||
|
while (diff >= 0) {
|
||||||
|
// n overlaps with next
|
||||||
if (next.gc) {
|
if (next.gc) {
|
||||||
if (diff >= 0) {
|
// gc is stronger, so reduce length of n
|
||||||
n.len -= diff
|
n.len -= diff
|
||||||
if (diff > next.len) {
|
if (diff >= next.len) {
|
||||||
// need to create another deletion after $next
|
// delete the missing range after next
|
||||||
// TODO: (may not be necessary, because this case shouldn't happen!)
|
diff = diff - next.len // missing range after next
|
||||||
// also this is supposed to return a deletion range. which one to choose? n or the new created deletion?
|
if (diff > 0) {
|
||||||
throw new Error('This case is not handled (on purpose!)')
|
yield* this.ds.put(n) // unneccessary? TODO!
|
||||||
|
yield* this.markDeleted([next.id[0], next.id[1] + next.len], diff)
|
||||||
}
|
}
|
||||||
} // else: everything is fine :)
|
}
|
||||||
|
break
|
||||||
} else {
|
} else {
|
||||||
if (diff >= 0) {
|
// we can extend n with next
|
||||||
if (diff > next.len) {
|
if (diff >= next.len) {
|
||||||
// may be neccessary to extend next.next!
|
// n is even longer than next
|
||||||
// TODO: (may not be necessary, because this case shouldn't happen!)
|
// get next.next, and try to extend it
|
||||||
throw new Error('This case is not handled (on purpose!)')
|
var _next = yield* this.ds.findNext(next.id)
|
||||||
|
yield* this.ds.delete(next.id)
|
||||||
|
if (_next == null || n.id[0] !== next.id[0]) {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
next = _next
|
||||||
|
diff = n.id[1] + n.len - next.id[1] // from next.start to n.end
|
||||||
|
// continue!
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// n just partially overlaps with next. extend n, delete next, and break this loop
|
||||||
n.len += next.len - diff
|
n.len += next.len - diff
|
||||||
yield* this.ds.delete(next.id)
|
yield* this.ds.delete(next.id)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -591,7 +606,11 @@ module.exports = function (Y/* :any */) {
|
|||||||
if (o.parentSub != null) {
|
if (o.parentSub != null) {
|
||||||
if (Y.utils.compareIds(parent.map[o.parentSub], o.id)) {
|
if (Y.utils.compareIds(parent.map[o.parentSub], o.id)) {
|
||||||
setParent = true
|
setParent = true
|
||||||
|
if (o.right != null) {
|
||||||
parent.map[o.parentSub] = o.right
|
parent.map[o.parentSub] = o.right
|
||||||
|
} else {
|
||||||
|
delete parent.map[o.parentSub]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Y.utils.compareIds(parent.start, o.id)) {
|
if (Y.utils.compareIds(parent.start, o.id)) {
|
||||||
@ -798,7 +817,7 @@ module.exports = function (Y/* :any */) {
|
|||||||
return ins
|
return ins
|
||||||
} else {
|
} else {
|
||||||
var left = Y.utils.copyObject(ins)
|
var left = Y.utils.copyObject(ins)
|
||||||
ins.content = left.content.splice(ins.id[1] - id[1])
|
ins.content = left.content.splice(id[1] - ins.id[1])
|
||||||
ins.id = id
|
ins.id = id
|
||||||
var leftLid = Y.utils.getLastId(left)
|
var leftLid = Y.utils.getLastId(left)
|
||||||
ins.origin = leftLid
|
ins.origin = leftLid
|
||||||
@ -823,7 +842,7 @@ module.exports = function (Y/* :any */) {
|
|||||||
return ins
|
return ins
|
||||||
} else {
|
} else {
|
||||||
var right = Y.utils.copyObject(ins)
|
var right = Y.utils.copyObject(ins)
|
||||||
right.content = ins.content.splice(-(ins.id[1] + ins.content.length - 1 - id[1])) // cut off remainder
|
right.content = ins.content.splice(id[1] - ins.id[1] + 1) // cut off remainder
|
||||||
right.id = [id[0], id[1] + 1]
|
right.id = [id[0], id[1] + 1]
|
||||||
var insLid = Y.utils.getLastId(ins)
|
var insLid = Y.utils.getLastId(ins)
|
||||||
right.origin = insLid
|
right.origin = insLid
|
||||||
|
Loading…
x
Reference in New Issue
Block a user