fixed crash when trying to select text in the text box via double click

- fixes #822
This commit is contained in:
Dmitry Stepanov
2025-07-05 09:58:11 +03:00
parent a813241d60
commit c2352503d9
+13 -7
View File
@@ -380,13 +380,19 @@ impl FormattedText {
}
fn position_to_char_index_internal(&self, position: Position, clamp: bool) -> Option<usize> {
self.lines.get(position.line).map(|line| {
line.begin
+ position.offset.min(if clamp {
line.len().saturating_sub(1)
} else {
line.len()
})
self.lines.get(position.line).and_then(|line| {
if line.is_empty() {
None
} else {
Some(
line.begin
+ position.offset.min(if clamp {
line.len().saturating_sub(1)
} else {
line.len()
}),
)
}
})
}
pub fn position_range_to_char_index_range(&self, range: Range<Position>) -> Range<usize> {