fixed merging and adapted writeStructs to write end of message
This commit is contained in:
@@ -168,6 +168,7 @@ export class AbstractItem extends AbstractStruct {
|
||||
} else {
|
||||
o = parent._start
|
||||
}
|
||||
// TODO: use something like DeleteSet here (a tree implementation would be best)
|
||||
/**
|
||||
* @type {Set<AbstractItem>}
|
||||
*/
|
||||
@@ -391,6 +392,20 @@ export class AbstractItem extends AbstractStruct {
|
||||
throw new Error('unimplemented')
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {AbstractItem} right
|
||||
* @return {boolean}
|
||||
*/
|
||||
mergeWith (right) {
|
||||
if (compareIDs(right.origin, this.lastId) && this.right === right && compareIDs(this.rightOrigin, right.rightOrigin)) {
|
||||
this.right = right.right
|
||||
if (right.right !== null) {
|
||||
right.right = this
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
/**
|
||||
* Mark this Item as deleted.
|
||||
*
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
changeItemRefOffset,
|
||||
GC,
|
||||
splitItem,
|
||||
compareIDs,
|
||||
addToDeleteSet,
|
||||
StructStore, Transaction, ID, AbstractType // eslint-disable-line
|
||||
} from '../internals.js'
|
||||
@@ -80,7 +79,7 @@ export class ItemDeleted extends AbstractItem {
|
||||
* @return {boolean}
|
||||
*/
|
||||
mergeWith (right) {
|
||||
if (compareIDs(right.origin, this.lastId) && this.right === right && compareIDs(this.rightOrigin, right.rightOrigin)) {
|
||||
if (super.mergeWith(right)) {
|
||||
this._len += right._len
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
getItemType,
|
||||
splitItem,
|
||||
changeItemRefOffset,
|
||||
compareIDs,
|
||||
GC,
|
||||
ItemDeleted,
|
||||
StructStore, Transaction, ID, AbstractType // eslint-disable-line
|
||||
@@ -75,7 +74,7 @@ export class ItemJSON extends AbstractItem {
|
||||
* @return {boolean}
|
||||
*/
|
||||
mergeWith (right) {
|
||||
if (compareIDs(right.origin, this.lastId) && this.right === right && compareIDs(this.rightOrigin, right.rightOrigin)) {
|
||||
if (super.mergeWith(right)) {
|
||||
this.content = this.content.concat(right.content)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
getItemType,
|
||||
splitItem,
|
||||
changeItemRefOffset,
|
||||
compareIDs,
|
||||
ItemDeleted,
|
||||
GC,
|
||||
StructStore, Transaction, ID, AbstractType // eslint-disable-line
|
||||
@@ -76,7 +75,7 @@ export class ItemString extends AbstractItem {
|
||||
* @return {boolean}
|
||||
*/
|
||||
mergeWith (right) {
|
||||
if (compareIDs(right.origin, this.lastId) && this.right === right && compareIDs(this.rightOrigin, right.rightOrigin)) {
|
||||
if (super.mergeWith(right)) {
|
||||
this.string += right.string
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user