WIP - Serialize buffer in terms of its state, not its base text + ops
The main reason for this is that we need to include information about a buffer's UndoMap into its protobuf representation. But it's a bit complex to correctly incorporate this information into the current protobuf representation. If we want to continue reusing `Buffer::apply_remote_edit` for incorporating the historical operations, we need to either make that method capable of incorporating already-undone edits, or serialize the UndoMap into undo *operations*, so that we can apply these undo operations after the fact when deserializing. But this is not trivial, because an UndoOperation requires information about the full offset ranges that were undone.
This commit is contained in:
parent
d7ecbdcc1d
commit
984e366c32
6 changed files with 222 additions and 44 deletions
|
@ -782,17 +782,30 @@ async fn test_empty_diagnostic_ranges(mut cx: gpui::TestAppContext) {
|
|||
|
||||
#[gpui::test]
|
||||
fn test_serialization(cx: &mut gpui::MutableAppContext) {
|
||||
let mut now = Instant::now();
|
||||
|
||||
let buffer1 = cx.add_model(|cx| {
|
||||
let mut buffer = Buffer::new(0, "abc", cx);
|
||||
buffer.edit([3..3], "DE", cx);
|
||||
buffer.edit([3..3], "D", cx);
|
||||
|
||||
now += Duration::from_secs(1);
|
||||
buffer.start_transaction_at(now);
|
||||
buffer.edit([4..4], "E", cx);
|
||||
buffer.end_transaction_at(now, cx);
|
||||
assert_eq!(buffer.text(), "abcDE");
|
||||
|
||||
buffer.undo(cx);
|
||||
assert_eq!(buffer.text(), "abcD");
|
||||
|
||||
buffer.edit([4..4], "F", cx);
|
||||
assert_eq!(buffer.text(), "abcDF");
|
||||
buffer
|
||||
});
|
||||
assert_eq!(buffer1.read(cx).text(), "abc");
|
||||
assert_eq!(buffer1.read(cx).text(), "abcDF");
|
||||
|
||||
let message = buffer1.read(cx).to_proto();
|
||||
let buffer2 = cx.add_model(|cx| Buffer::from_proto(1, message, None, cx).unwrap());
|
||||
assert_eq!(buffer2.read(cx).text(), "abc");
|
||||
assert_eq!(buffer2.read(cx).text(), "abcDF");
|
||||
}
|
||||
|
||||
fn chunks_with_diagnostics<T: ToOffset + ToPoint>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue