on master help sign in
Avoid theoretical underflow.
commit09a7db637e028cac5f5b035e7084838d2a608897 authorJakub Bartodziej <jqb@google.com> dateThu 3 Jun 2021, 10:10 (5 years ago) parent31ed4db
1 file changed+2−3
helix-term/src/commands.rs+2−3
helix-term/src/commands.rs+2−3
@@ -759,9 +759,8 @@ fn _delete_selection(doc: &mut Document, view_id: ViewId) {
759759 // then delete
760760 let transaction =
761761 Transaction::change_by_selection(doc.text(), doc.selection(view_id), |range| {
762− use std::cmp::{max, min};
763− let max_to = max(0, doc.text().len_chars() - 1);
764− let to = min(max_to, range.to() + 1);
762+ let max_to = doc.text().len_chars().saturating_sub(1);
763+ let to = std::cmp::min(max_to, range.to() + 1);
765764 (range.from(), to, None)
766765 });
767766 doc.apply(&transaction, view_id);