fixed pos.rel cases

This commit is contained in:
Kevin Jahns
2021-11-21 19:53:53 +01:00
parent 40c3be1732
commit 2a33507c00
4 changed files with 65 additions and 9 deletions

View File

@@ -162,13 +162,18 @@ export class ListIterator {
/**
* @param {Transaction} tr
* @param {number} len
* @return {ListIterator}
*/
backward (tr, len) {
if (this.index - len < 0) {
throw lengthExceeded
}
let item = this.nextItem && this.nextItem.left
this.index -= len
if (this.rel > len) {
this.rel -= len
return this
}
let item = this.nextItem && this.nextItem.left
if (this.rel) {
len -= this.rel
this.rel = 0
@@ -177,8 +182,10 @@ export class ListIterator {
if (item.countable && !item.deleted && item.moved === this.currMove) {
len -= item.length
if (len < 0) {
this.rel = item.length + len
this.rel = -len
len = 0
}
if (len === 0) {
break
}
} else if (item.content.constructor === ContentMove && item.moved === this.currMove) {
@@ -201,8 +208,7 @@ export class ListIterator {
}
item = item.left
}
this.index -= len
this.nextItem = item && item.right
this.nextItem = item
return this
}