fix: textchange can be both delete and insert

This commit is contained in:
əlemi 2024-08-14 23:46:16 +02:00
parent a5502d1f1f
commit e43105b919
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -100,11 +100,13 @@ impl ControllerWorker<TextChange> for BufferWorker {
let agent_id = oplog.get_or_create_agent_id(&self.user_id.to_string()); let agent_id = oplog.get_or_create_agent_id(&self.user_id.to_string());
let last_ver = oplog.local_version(); let last_ver = oplog.local_version();
if change.is_delete() {
branch.delete_without_content(&mut oplog, 1, change.span());
}
if change.is_insert() { if change.is_insert() {
branch.insert(&mut oplog, agent_id, change.start as usize, &change.content) branch.insert(&mut oplog, agent_id, change.start as usize, &change.content);
} else if change.is_delete() { }
branch.delete_without_content(&mut oplog, 1, change.span())
} else { continue; };
tx.send(Operation { data: oplog.encode_from(Default::default(), &last_ver) }).await tx.send(Operation { data: oplog.encode_from(Default::default(), &last_ver) }).await
.unwrap_or_warn("failed to send change!"); .unwrap_or_warn("failed to send change!");