Skip to content

Commit

Permalink
Fix prefix_usv_index, it's actually the index at which the diff starts
Browse files Browse the repository at this point in the history
  • Loading branch information
DataTriny committed May 26, 2024
1 parent ab895d1 commit 75d8080
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions platforms/atspi-common/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,16 @@ impl<'a> AdapterChangeHandler<'a> {

let mut old_chars = old_text.chars();
let mut new_chars = new_text.chars();
let mut prefix_usv_index = 0;
let mut prefix_usv_count = 0;
let mut prefix_byte_count = 0;
loop {
match (old_chars.next(), new_chars.next()) {
(Some(old_char), Some(new_char)) if old_char == new_char => {
prefix_usv_index += 1;
prefix_usv_count += 1;
prefix_byte_count += new_char.len_utf8();
}
(None, None) => return,
_ => {
prefix_usv_index += 1;
break;
}
_ => break,
}
}

Expand All @@ -120,7 +117,7 @@ impl<'a> AdapterChangeHandler<'a> {
self.adapter.emit_object_event(
id,
ObjectEvent::TextRemoved {
start_index: prefix_usv_index,
start_index: prefix_usv_count,
length,
content: old_content.to_string(),
},
Expand All @@ -134,7 +131,7 @@ impl<'a> AdapterChangeHandler<'a> {
self.adapter.emit_object_event(
id,
ObjectEvent::TextInserted {
start_index: prefix_usv_index,
start_index: prefix_usv_count,
length,
content: new_content.to_string(),
},
Expand Down

0 comments on commit 75d8080

Please sign in to comment.