reinit search marker after transaction
This commit is contained in:
parent
0948229422
commit
4356d70ed0
@ -54,6 +54,8 @@ export const useSearchMarker = (tr, yarray, index, f) => {
|
|||||||
const prevItem = /** @type {Item} */ (sm.nextItem)
|
const prevItem = /** @type {Item} */ (sm.nextItem)
|
||||||
if (createFreshMarker) {
|
if (createFreshMarker) {
|
||||||
searchMarker.push(fsm)
|
searchMarker.push(fsm)
|
||||||
|
} else {
|
||||||
|
fsm.reinit(tr)
|
||||||
}
|
}
|
||||||
const diff = fsm.index - index
|
const diff = fsm.index - index
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
|
@ -124,14 +124,16 @@ export class YArray extends AbstractType {
|
|||||||
* @param {Array<T>} content The array of content
|
* @param {Array<T>} content The array of content
|
||||||
*/
|
*/
|
||||||
insert (index, content) {
|
insert (index, content) {
|
||||||
if (this.doc !== null) {
|
if (content.length > 0) {
|
||||||
transact(this.doc, transaction => {
|
if (this.doc !== null) {
|
||||||
useSearchMarker(transaction, this, index, walker =>
|
transact(this.doc, transaction => {
|
||||||
walker.insertArrayValue(transaction, content)
|
useSearchMarker(transaction, this, index, walker =>
|
||||||
)
|
walker.insertArrayValue(transaction, content)
|
||||||
})
|
)
|
||||||
} else {
|
})
|
||||||
/** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content)
|
} else {
|
||||||
|
/** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as error from 'lib0/error'
|
import * as error from 'lib0/error'
|
||||||
|
import { getItem } from 'yjs'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getItemCleanStart,
|
getItemCleanStart,
|
||||||
@ -73,6 +74,18 @@ export class ListIterator {
|
|||||||
return iter
|
return iter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Transaction} tr
|
||||||
|
*/
|
||||||
|
reinit (tr) {
|
||||||
|
if (this.nextItem) {
|
||||||
|
const nextId = this.nextItem.id
|
||||||
|
const reinitId = createID(nextId.client, nextId.clock + this.rel)
|
||||||
|
this.nextItem = getItem(tr.doc.store, reinitId)
|
||||||
|
this.rel = reinitId.clock - this.nextItem.id.clock
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Item | null}
|
* @type {Item | null}
|
||||||
*/
|
*/
|
||||||
@ -333,7 +346,7 @@ export class ListIterator {
|
|||||||
left = new Item(createID(ownClientId, getState(store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, c)
|
left = new Item(createID(ownClientId, getState(store, ownClientId)), left, left && left.lastId, right, right && right.id, parent, null, c)
|
||||||
left.integrate(tr, 0)
|
left.integrate(tr, 0)
|
||||||
})
|
})
|
||||||
if (right === null && left !== null) {
|
if (right === null) {
|
||||||
this.nextItem = left
|
this.nextItem = left
|
||||||
this.reachedEnd = true
|
this.reachedEnd = true
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user