fix crash by rope bytes

This commit is contained in:
light-ly 2024-10-26 18:50:42 +08:00
parent a749580bdb
commit d903f37e73

View File

@ -768,7 +768,8 @@ impl LSPSupport for Rope {
}
fn byte_to_pos(&self, byte_idx: usize) -> Position {
// info!("byte_idx: {byte_idx}");
return self.char_to_pos(self.byte_to_char(min(byte_idx, self.len_bytes() - 1)));
let self_len = if self.len_bytes() != 0 { self.len_bytes() - 1 } else { 0 };
return self.char_to_pos(self.byte_to_char(min(byte_idx, self_len)));
}
fn char_to_pos(&self, char_idx: usize) -> Position {
let line = self.char_to_line(char_idx);