Delete all children of ItemType when it is deleted
This commit is contained in:
@@ -425,6 +425,7 @@ export class AbstractItem extends AbstractStruct {
|
||||
* @private
|
||||
*/
|
||||
gc (transaction, store) {
|
||||
this.delete(transaction)
|
||||
let r
|
||||
if (this.parent._item !== null && this.parent._item.deleted) {
|
||||
r = new GC(this.id, this.length)
|
||||
|
||||
@@ -100,9 +100,21 @@ export class ItemType extends AbstractItem {
|
||||
* @private
|
||||
*/
|
||||
delete (transaction) {
|
||||
super.delete(transaction)
|
||||
transaction.changed.delete(this.type)
|
||||
transaction.changedParentTypes.delete(this.type)
|
||||
if (!this.deleted) {
|
||||
super.delete(transaction)
|
||||
let item = this.type._start
|
||||
while (item !== null) {
|
||||
if (!item.deleted) {
|
||||
item.delete(transaction)
|
||||
}
|
||||
item = item.right
|
||||
}
|
||||
this.type._map.forEach(item => {
|
||||
item.delete(transaction)
|
||||
})
|
||||
transaction.changed.delete(this.type)
|
||||
transaction.changedParentTypes.delete(this.type)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -454,13 +454,10 @@ export const typeArrayDelete = (transaction, parent, index, length) => {
|
||||
if (length === 0) { return }
|
||||
let n = parent._start
|
||||
// compute the first item to be deleted
|
||||
for (; n !== null; n = n.right) {
|
||||
for (; n !== null && index > 0; n = n.right) {
|
||||
if (!n.deleted && n.countable) {
|
||||
if (index <= n.length) {
|
||||
if (index < n.length && index > 0) {
|
||||
n = getItemCleanStart(transaction, transaction.y.store, createID(n.id.client, n.id.clock + index))
|
||||
}
|
||||
break
|
||||
if (index < n.length) {
|
||||
getItemCleanStart(transaction, transaction.y.store, createID(n.id.client, n.id.clock + index))
|
||||
}
|
||||
index -= n.length
|
||||
}
|
||||
|
||||
@@ -165,9 +165,9 @@ export const transact = (y, f) => {
|
||||
// transaction cleanup
|
||||
const store = transaction.y.store
|
||||
const ds = transaction.deleteSet
|
||||
// replace deleted items with ItemDeleted / GC
|
||||
sortAndMergeDeleteSet(ds)
|
||||
y.emit('afterTransaction', [transaction, y])
|
||||
// replace deleted items with ItemDeleted / GC
|
||||
for (const [client, deleteItems] of ds.clients) {
|
||||
/**
|
||||
* @type {Array<AbstractStruct>}
|
||||
|
||||
@@ -270,8 +270,5 @@ export const createAbsolutePositionFromCursor = (cursor, y) => {
|
||||
* @function
|
||||
*/
|
||||
export const compareCursors = (a, b) => a === b || (
|
||||
a !== null && b !== null && a.tname === b.tname && (
|
||||
(a.item !== null && b.item !== null && compareIDs(a.item, b.item)) ||
|
||||
(a.type !== null && b.type !== null && compareIDs(a.type, b.type))
|
||||
)
|
||||
a !== null && b !== null && a.tname === b.tname && compareIDs(a.item, b.item) && compareIDs(a.type, b.type)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user