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

Add Text::update #44

Merged
merged 1 commit into from
Jan 30, 2024
Merged

Add Text::update #44

merged 1 commit into from
Jan 30, 2024

Conversation

alexjg
Copy link
Collaborator

@alexjg alexjg commented Dec 12, 2023

Problem: sometimes when modifying text you are not able to capture the edits to the text field as they happen. For example, if the text is in a file and you just get notified when the file has changed then you have no way of knowing which text was inserted and deleted. The Text API requires that you express all changes as splice calls, so the user is forced to figure out how to turn the new value into a set of splice calls, which can be tricky.

Solution: add Text::update, which performs an LCS diff to figure out a minimal set of splice calls to perform internally.

Problem: sometimes when modifying text you are not able to capture the
edits to the text field as they happen. For example, if the text is in a
file and you just get notified when the file has changed then you have
no way of knowing which text was inserted and deleted. The `Text` API
requires that you express all changes as `splice` calls, so the user is
forced to figure out how to turn the new value into a set of `splice`
calls, which can be tricky.

Solution: add `Text::update`, which performs an LCS diff to figure out a
minimal set of `splice` calls to perform internally.
@tdomhan
Copy link

tdomhan commented Jan 30, 2024

This looks useful.
How does this relate to automerge/automerge@26472cd ?
With the updateText in automerge would you call that directly?

@alexjg
Copy link
Collaborator Author

alexjg commented Jan 30, 2024

Man I forgot I didn't merge this PR, I'm going to do that now.

Re. automerge::update_text, we couldn't use that here because the purpose of Text is to accumulate changes when you don't have mutable access to an automerge::Automerge for whatever reason. The result is ultimately the same (a sequence of splice calls based on the diff) and even uses the same algorithm because in the implementation of automerge::update_text I just cribbed the myers diff implementation from similar (with appropriate attribution of course) which is what we use here.

@alexjg alexjg merged commit 3a952ff into main Jan 30, 2024
8 checks passed
@tdomhan
Copy link

tdomhan commented Jan 30, 2024

Makes sense, thanks!

@alexjg
Copy link
Collaborator Author

alexjg commented Jan 30, 2024

Published in 0.8.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants