Create Structs based on offset, if necessary
implement offset parameter in Ref.toStruct
This commit is contained in:
@@ -10,6 +10,8 @@ import {
|
||||
getItemCleanEnd,
|
||||
getItemCleanStart,
|
||||
getItemType,
|
||||
changeItemRefOffset,
|
||||
GC,
|
||||
Transaction, ID, AbstractType // eslint-disable-line
|
||||
} from '../internals.js'
|
||||
|
||||
@@ -84,17 +86,36 @@ export class ItemDeletedRef extends AbstractItemRef {
|
||||
}
|
||||
/**
|
||||
* @param {Transaction} transaction
|
||||
* @return {ItemDeleted}
|
||||
* @param {number} offset
|
||||
* @return {ItemDeleted|GC}
|
||||
*/
|
||||
toStruct (transaction) {
|
||||
toStruct (transaction, offset) {
|
||||
const y = transaction.y
|
||||
const store = y.store
|
||||
if (offset > 0) {
|
||||
changeItemRefOffset(this, offset)
|
||||
this.len = this.len - offset
|
||||
}
|
||||
|
||||
let parent
|
||||
if (this.parent !== null) {
|
||||
const parentItem = getItemType(store, this.parent)
|
||||
switch (parentItem.constructor) {
|
||||
case ItemDeleted:
|
||||
case GC:
|
||||
return new GC(this.id, 1)
|
||||
}
|
||||
parent = parentItem.type
|
||||
} else {
|
||||
// @ts-ignore
|
||||
parent = y.get(this.parentYKey)
|
||||
}
|
||||
|
||||
return new ItemDeleted(
|
||||
this.id,
|
||||
this.left === null ? null : getItemCleanEnd(store, transaction, this.left),
|
||||
this.right === null ? null : getItemCleanStart(store, transaction, this.right),
|
||||
// @ts-ignore
|
||||
this.parent === null ? y.get(this.parentYKey) : getItemType(store, this.parent).type,
|
||||
parent,
|
||||
this.parentSub,
|
||||
this.len
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user