group cleanups for YText changes into a single transaction

Fixes #522 but is still massively slow
This commit is contained in:
Noel Levy
2023-06-12 16:56:19 -07:00
parent 00ef472d68
commit 3741f43a11
2 changed files with 22 additions and 2 deletions

View File

@@ -859,12 +859,21 @@ export class YText extends AbstractType {
_callObserver (transaction, parentSubs) {
super._callObserver(transaction, parentSubs)
const event = new YTextEvent(this, transaction, parentSubs)
const doc = transaction.doc
callTypeObservers(this, transaction, event)
// If a remote change happened, we try to cleanup potential formatting duplicates.
if (!transaction.local) {
transaction._yTexts.push(this)
}
}
/**
* @param {Transaction} transaction
*/
_cleanup (transaction) {
if (!transaction.local) {
// check if another formatting item was inserted
let foundFormattingItem = false
const doc = transaction.doc
for (const [client, afterClock] of transaction.afterState.entries()) {
const clock = transaction.beforeState.get(client) || 0
if (afterClock === clock) {