We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d226a17 commit 76e6106Copy full SHA for 76e6106
editors/vi/buffer/line.rs
@@ -5,12 +5,14 @@
5
/// Returns the index of the first character whose byte offset is >= the given byte offset,
6
/// or the total character count if byte_offset is past the end.
7
pub fn char_index_at_byte(content: &str, byte_offset: usize) -> usize {
8
- content
9
- .char_indices()
10
- .enumerate()
11
- .find(|(_, (b, _))| *b >= byte_offset)
12
- .map(|(i, _)| i)
13
- .unwrap_or_else(|| content.chars().count())
+ let mut char_index = 0usize;
+ for (b, _) in content.char_indices() {
+ if b >= byte_offset {
+ return char_index;
+ }
+ char_index += 1;
14
15
+ char_index
16
}
17
18
/// A single line in the edit buffer.
0 commit comments