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

LoroText.update(targetStr) may not capture the edit intent #543

Closed
zxch3n opened this issue Nov 7, 2024 · 0 comments · Fixed by #544
Closed

LoroText.update(targetStr) may not capture the edit intent #543

zxch3n opened this issue Nov 7, 2024 · 0 comments · Fixed by #544
Assignees
Labels
bug Something isn't working

Comments

@zxch3n
Copy link
Member

zxch3n commented Nov 7, 2024

The current .update(targetStr) will calculate the difference based on the Myers diff. Although the computed difference has minimal edits, the difference can be very counterintuitive:

import { expect, it, describe, beforeEach } from 'vitest';
import { LoroDoc } from 'loro-crdt';

it('sync', () => {
  const docA = new LoroDoc();
  const docB = new LoroDoc();
  docA.setPeerId(1);
  docB.setPeerId(0);
  docA.getText('text').update('Hello');
  docB.import(
    docA.export({
      mode: 'update',
    })
  );

  const textA = docA.getText('text');
  textA.update('Oh, Hello World!\nThis sentence should stay untouched!');

  const textB = docB.getText('text');
  textB.update('Hmmm, Hello Alice!');

  docA.import(docB.export({ mode: 'update' }));
  docB.import(docA.export({ mode: 'update' }));
  console.dir(docA.exportJsonUpdates(), { depth: 100 });

  expect(docA.getText('text').toString()).toBe(
    'Oh, Hmmm, Hello World! Alice!\nThis sentence should stay untouched!'
  );

  // - Oh, Hmmm, Hello World! Alice!
  // + Oh, Hmmm, Hello World!
  // - This sentence should stay untouched!
  // + This sentence should stay unto Alice!uched!
});

https://stackblitz.com/edit/stackblitz-starters-2lf3ty?file=loro.test.js

The diagram of the cause of the issue:

CleanShot 2024-11-07 at 08 55 02@2x

@zxch3n zxch3n added the bug Something isn't working label Nov 7, 2024
@zxch3n zxch3n self-assigned this Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant