-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
4 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use autosurgeon::Text; | ||
use autosurgeon::{Hydrate, Reconcile}; | ||
|
||
#[derive(Hydrate, Reconcile)] | ||
struct TextDoc { | ||
content: Text, | ||
} | ||
|
||
#[test] | ||
fn diff_generates_splices() { | ||
let start = TextDoc { | ||
content: Text::with_value("some value"), | ||
}; | ||
|
||
let mut doc = automerge::AutoCommit::new(); | ||
autosurgeon::reconcile(&mut doc, &start).unwrap(); | ||
let mut doc2 = doc.fork(); | ||
|
||
let mut start2 = autosurgeon::hydrate::<_, TextDoc>(&doc).unwrap(); | ||
start2.content.update("some day"); | ||
autosurgeon::reconcile(&mut doc, &start2).unwrap(); | ||
|
||
let mut start3 = autosurgeon::hydrate::<_, TextDoc>(&doc2).unwrap(); | ||
start3.content.update("another value"); | ||
autosurgeon::reconcile(&mut doc2, &start3).unwrap(); | ||
|
||
doc.merge(&mut doc2).unwrap(); | ||
|
||
let start3 = autosurgeon::hydrate::<_, TextDoc>(&doc).unwrap(); | ||
assert_eq!(start3.content.as_str(), "another day"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters