editor: Apply common_prefix_len
refactor suggestion (#31957)
This adds João's nice suggestion from https://github.com/zed-industries/zed/pull/31818#discussion_r2118582616. Release Notes: - N/A --------- Co-authored-by: João Marcos <marcospb19@hotmail.com>
This commit is contained in:
parent
27d3da678c
commit
b9256dd469
1 changed files with 6 additions and 8 deletions
|
@ -5550,14 +5550,12 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
|
||||
let mut common_prefix_len = 0;
|
||||
for (a, b) in old_text.chars().zip(new_text.chars()) {
|
||||
if a == b {
|
||||
common_prefix_len += a.len_utf8();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let common_prefix_len = old_text
|
||||
.chars()
|
||||
.zip(new_text.chars())
|
||||
.take_while(|(a, b)| a == b)
|
||||
.map(|(a, _)| a.len_utf8())
|
||||
.sum::<usize>();
|
||||
|
||||
cx.emit(EditorEvent::InputHandled {
|
||||
utf16_range_to_replace: None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue