Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yText delta attributes is not correct when undo #620

Open
caifenglei opened this issue Mar 5, 2024 · 0 comments
Open

yText delta attributes is not correct when undo #620

caifenglei opened this issue Mar 5, 2024 · 0 comments
Assignees
Labels

Comments

@caifenglei
Copy link

Describe the bug
yText delta attributes are not correct when undo.

To Reproduce
Steps to reproduce the behavior:

  1. ClientA: insert text S and AAAAA
  2. ClientB: insert BBB in AAAAA
  3. ClientA: undo
  4. BBB's attribute is using S's, but not its origin value

Expected behavior
BBB's attribute is its origin set value

Screenshots
image

Environment Information

  • Yjs version 13.6.14

Additional context
vue demo code:

    // Client A
    const ydoc = new Y.Doc()
    const ymap = ydoc.getMap("root")
    const contentText = new Y.Text()
    const propertyMap = new Y.Map()
    ymap.set('docContent', contentText)
    ymap.set('propertyMap', propertyMap)
    const undoManager = new Y.UndoManager(ymap, {trackedOrigins: new Set(['trackUndo'])})
    ymap.observeDeep((events: Y.YEvent<any>[], transaction: Y.Transaction) => {
      console.info(events, 'events A>>>>>>>>>>>>')
    })

    ydoc.transact(() => {
      contentText.insert(0, 'S', {type: 'MK_E_9', id: 'C_000'})
    }, 'trackUndo')

    undoManager.stopCapturing()
    ydoc.transact(() => {
      contentText.insert(1, 'AAAAA', {type: '10', id: 'C_001'})
      previewText('ClientA insert S and AAAAA', contentText)
    }, 'trackUndo')

    //Client B
    const ydocRemote = new Y.Doc()
    syncA2B(ydoc, ydocRemote)
    
    const ymapRemote = ydocRemote.getMap("root")
    const propertyMapB = ymapRemote.get('propertyMap') as Y.Map<any>
    const contentTextB = ymapRemote.get('docContent') as Y.Text

    contentTextB.insert(3, 'BBB', {type: '10', id: 'C_003'})
    syncB2A(ydocRemote, ydoc)
    previewText('ClientB insert BBB in AAAAA', contentText)

    //Client A
    undoManager.undo()
    previewText('ClientA undo', contentText)


    function syncA2B(ydocA, ydocB) {
    Y.applyUpdate(ydocB, Y.encodeStateAsUpdate(ydocA))
  }

  function syncB2A(ydocB, ydocA) {
    Y.applyUpdate(ydocA, Y.encodeStateAsUpdate(ydocB))
  }

  function previewText(desc:string, yText: Y.Text) {
    previewTexts.value.push({delta: yText.toDelta(), content: yText.toString(), desc: desc})
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants