mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-23 01:46:18 +04:00
Avoid theoretical underflow.
This commit is contained in:
parent
31ed4db153
commit
09a7db637e
@ -759,9 +759,8 @@ fn _delete_selection(doc: &mut Document, view_id: ViewId) {
|
|||||||
// then delete
|
// then delete
|
||||||
let transaction =
|
let transaction =
|
||||||
Transaction::change_by_selection(doc.text(), doc.selection(view_id), |range| {
|
Transaction::change_by_selection(doc.text(), doc.selection(view_id), |range| {
|
||||||
use std::cmp::{max, min};
|
let max_to = doc.text().len_chars().saturating_sub(1);
|
||||||
let max_to = max(0, doc.text().len_chars() - 1);
|
let to = std::cmp::min(max_to, range.to() + 1);
|
||||||
let to = min(max_to, range.to() + 1);
|
|
||||||
(range.from(), to, None)
|
(range.from(), to, None)
|
||||||
});
|
});
|
||||||
doc.apply(&transaction, view_id);
|
doc.apply(&transaction, view_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user