skip iterating when there are no formatting items - replaces #547
This commit is contained in:
parent
b792902f17
commit
981340139f
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
AbstractType, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Item, StructStore, Transaction // eslint-disable-line
|
YText, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Item, StructStore, Transaction // eslint-disable-line
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
import * as error from 'lib0/error'
|
import * as error from 'lib0/error'
|
||||||
@ -47,28 +47,30 @@ export class ContentFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} offset
|
* @param {number} _offset
|
||||||
* @return {ContentFormat}
|
* @return {ContentFormat}
|
||||||
*/
|
*/
|
||||||
splice (offset) {
|
splice (_offset) {
|
||||||
throw error.methodUnimplemented()
|
throw error.methodUnimplemented()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ContentFormat} right
|
* @param {ContentFormat} _right
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
mergeWith (right) {
|
mergeWith (_right) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Transaction} transaction
|
* @param {Transaction} _transaction
|
||||||
* @param {Item} item
|
* @param {Item} item
|
||||||
*/
|
*/
|
||||||
integrate (transaction, item) {
|
integrate (_transaction, item) {
|
||||||
// @todo searchmarker are currently unsupported for rich text documents
|
// @todo searchmarker are currently unsupported for rich text documents
|
||||||
/** @type {AbstractType<any>} */ (item.parent)._searchMarker = null
|
const p = /** @type {YText} */ (item.parent)
|
||||||
|
p._searchMarker = null
|
||||||
|
p._hasFormatting = true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -505,7 +505,7 @@ export const cleanupYTextAfterTransaction = transaction => {
|
|||||||
// cleanup in a new transaction
|
// cleanup in a new transaction
|
||||||
transact(doc, (t) => {
|
transact(doc, (t) => {
|
||||||
iterateDeletedStructs(transaction, transaction.deleteSet, item => {
|
iterateDeletedStructs(transaction, transaction.deleteSet, item => {
|
||||||
if (item instanceof GC || needFullCleanup.has(/** @type {YText} */ (item.parent))) {
|
if (item instanceof GC || !(/** @type {YText} */ (item.parent)._hasFormatting) || needFullCleanup.has(/** @type {YText} */ (item.parent))) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const parent = /** @type {YText} */ (item.parent)
|
const parent = /** @type {YText} */ (item.parent)
|
||||||
@ -859,9 +859,14 @@ export class YText extends AbstractType {
|
|||||||
*/
|
*/
|
||||||
this._pending = string !== undefined ? [() => this.insert(0, string)] : []
|
this._pending = string !== undefined ? [() => this.insert(0, string)] : []
|
||||||
/**
|
/**
|
||||||
* @type {Array<ArraySearchMarker>}
|
* @type {Array<ArraySearchMarker>|null}
|
||||||
*/
|
*/
|
||||||
this._searchMarker = []
|
this._searchMarker = []
|
||||||
|
/**
|
||||||
|
* Whether this YText contains formatting attributes.
|
||||||
|
* This flag is updated when a formatting item is integrated (see ContentFormat.integrate)
|
||||||
|
*/
|
||||||
|
this._hasFormatting = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -911,7 +916,7 @@ export class YText extends AbstractType {
|
|||||||
const event = new YTextEvent(this, transaction, parentSubs)
|
const event = new YTextEvent(this, transaction, parentSubs)
|
||||||
callTypeObservers(this, transaction, event)
|
callTypeObservers(this, transaction, event)
|
||||||
// If a remote change happened, we try to cleanup potential formatting duplicates.
|
// If a remote change happened, we try to cleanup potential formatting duplicates.
|
||||||
if (!transaction.local) {
|
if (!transaction.local && this._hasFormatting) {
|
||||||
transaction._needFormattingCleanup = true
|
transaction._needFormattingCleanup = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user