diff options
author | Jakub Bartodziej | 2021-06-03 14:10:10 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-03 14:23:23 +0000 |
commit | 09a7db637e028cac5f5b035e7084838d2a608897 (patch) | |
tree | d62fd8acd085d6f5bf3a839ef034278db36331a2 | |
parent | 31ed4db1537dba80f81e26a66742a0f497172f03 (diff) |
Avoid theoretical underflow.
-rw-r--r-- | helix-term/src/commands.rs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e5135443..4a4816a0 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -759,9 +759,8 @@ fn _delete_selection(doc: &mut Document, view_id: ViewId) { // then delete let transaction = Transaction::change_by_selection(doc.text(), doc.selection(view_id), |range| { - use std::cmp::{max, min}; - let max_to = max(0, doc.text().len_chars() - 1); - let to = min(max_to, range.to() + 1); + let max_to = doc.text().len_chars().saturating_sub(1); + let to = std::cmp::min(max_to, range.to() + 1); (range.from(), to, None) }); doc.apply(&transaction, view_id); |