Skip to content

Commit

Permalink
fix: textchange can be both delete and insert
Browse files Browse the repository at this point in the history
  • Loading branch information
alemidev committed Aug 14, 2024
1 parent a5502d1 commit e43105b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/buffer/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ impl ControllerWorker<TextChange> for BufferWorker {
let agent_id = oplog.get_or_create_agent_id(&self.user_id.to_string());
let last_ver = oplog.local_version();

if change.is_delete() {
branch.delete_without_content(&mut oplog, 1, change.span());
}

if change.is_insert() {
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; };
branch.insert(&mut oplog, agent_id, change.start as usize, &change.content);
}

tx.send(Operation { data: oplog.encode_from(Default::default(), &last_ver) }).await
.unwrap_or_warn("failed to send change!");
Expand Down

0 comments on commit e43105b

Please sign in to comment.