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
|
@ -287,13 +287,24 @@ impl Buffer {
|
|||
file: Option<Box<dyn File>>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<Self> {
|
||||
let mut buffer =
|
||||
text::Buffer::new(replica_id, message.id, History::new(message.content.into()));
|
||||
let ops = message
|
||||
.history
|
||||
.into_iter()
|
||||
.map(|op| text::Operation::Edit(proto::deserialize_edit_operation(op)));
|
||||
buffer.apply_ops(ops)?;
|
||||
let mut fragments_len = message.fragments.len();
|
||||
let buffer = TextBuffer::from_parts(
|
||||
replica_id,
|
||||
message.id,
|
||||
message.content,
|
||||
message.deleted_content,
|
||||
message
|
||||
.undo_map
|
||||
.into_iter()
|
||||
.map(proto::deserialize_undo_map_entry),
|
||||
message
|
||||
.fragments
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, fragment)| {
|
||||
proto::deserialize_buffer_fragment(fragment, i, fragments_len)
|
||||
}),
|
||||
);
|
||||
let mut this = Self::build(buffer, file);
|
||||
for selection_set in message.selections {
|
||||
this.remote_selections.insert(
|
||||
|
@ -320,11 +331,18 @@ impl Buffer {
|
|||
pub fn to_proto(&self) -> proto::Buffer {
|
||||
proto::Buffer {
|
||||
id: self.remote_id(),
|
||||
content: self.text.base_text().to_string(),
|
||||
history: self
|
||||
content: self.text.text(),
|
||||
deleted_content: self.text.deleted_text(),
|
||||
undo_map: self
|
||||
.text
|
||||
.history()
|
||||
.map(proto::serialize_edit_operation)
|
||||
.undo_history()
|
||||
.map(proto::serialize_undo_map_entry)
|
||||
.collect(),
|
||||
version: proto::serialize_vector_clock(&self.version),
|
||||
fragments: self
|
||||
.text
|
||||
.fragments()
|
||||
.map(proto::serialize_buffer_fragment)
|
||||
.collect(),
|
||||
selections: self
|
||||
.remote_selections
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue