node_modules/yjs/dist/tests.js
/**
     * Creates YTextEvent and calls observers.
     *
     * @param {Transaction} transaction
     * @param {Set<null|string>} parentSubs Keys changed on this type. `null` if list was modified.
     */
Creates YTextEvent and calls observers.
@param {Transaction} transaction
@param {Set} parentSubs Keys changed on this type. `null` if list was modified.
Creates YTextEvent and calls observers . @param { Transaction } transaction @param { Set } parentSubs Keys changed on this type . ` null ` if list was modified .
_callObserver (transaction, parentSubs) {
      super._callObserver(transaction, parentSubs);
      const event = new YTextEvent(this, transaction, parentSubs);
      const doc = transaction.doc;
      if (!transaction.local) {
        let foundFormattingItem = false;
        for (const [client, afterClock] of transaction.afterState.entries()) {
          const clock = transaction.beforeState.get(client) || 0;
          if (afterClock === clock) {
            continue
          }
          iterateStructs(transaction,  (doc.store.clients.get(client)), clock, afterClock, item => {
            if (!item.deleted &&  (item).content.constructor === ContentFormat) {
              foundFormattingItem = true;
            }
          });
          if (foundFormattingItem) {
            break
          }
        }
        if (!foundFormattingItem) {
          iterateDeletedStructs(transaction, transaction.deleteSet, item => {
            if (item instanceof GC || foundFormattingItem) {
              return
            }
            if (item.parent === this && item.content.constructor === ContentFormat) {
              foundFormattingItem = true;
            }
          });
        }
        transact(doc, (t) => {
          if (foundFormattingItem) {
            cleanupYTextFormatting(this);
          } else {
            iterateDeletedStructs(t, t.deleteSet, item => {
              if (item instanceof GC) {
                return
              }
              if (item.parent === this) {
                cleanupContextlessFormattingGap(t, item);
              }
            });
          }
        });
      }
      callTypeObservers(this, transaction, event);
    }
_callObserver ( transaction , parentSubs ) { super . _callObserver ( transaction , parentSubs ) ; const event = new YTextEvent ( this , transaction , parentSubs ) ; const doc = transaction . doc ; if ( ! transaction . local ) { let foundFormattingItem = false ; for ( const [ client , afterClock ] of transaction . afterState . entries ( ) ) { const clock = transaction . beforeState . get ( client ) || 0 ; if ( afterClock === clock ) { continue } iterateStructs ( transaction , ( doc . store . clients . get ( client ) ) , clock , afterClock , item => { if ( ! item . deleted && ( item ) . content . constructor === ContentFormat ) { foundFormattingItem = true ; } } ) ; if ( foundFormattingItem ) { break } } if ( ! foundFormattingItem ) { iterateDeletedStructs ( transaction , transaction . deleteSet , item => { if ( item instanceof GC || foundFormattingItem ) { return } if ( item . parent === this && item . content . constructor === ContentFormat ) { foundFormattingItem = true ; } } ) ; } transact ( doc , ( t ) => { if ( foundFormattingItem ) { cleanupYTextFormatting ( this ) ; } else { iterateDeletedStructs ( t , t . deleteSet , item => { if ( item instanceof GC ) { return } if ( item . parent === this ) { cleanupContextlessFormattingGap ( t , item ) ; } } ) ; } } ) ; } callTypeObservers ( this , transaction , event ) ; }
Creates YTextEvent and calls observers.
Creates YTextEvent and calls observers .
// If a remote change happened, we try to cleanup potential formatting duplicates. // check if another formatting item was inserted /** @type {Array<Item|GC>} */ /** @type {Item} */ // If a formatting item was inserted, we simply clean the whole type. // We need to compute currentAttributes for the current position anyway. // If no formatting attribute was inserted, we can make due with contextless // formatting cleanups. // Contextless: it is not necessary to compute currentAttributes for the affected position.