diff options
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r-- | helix-term/src/commands.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index bc54abaa..cd053266 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1318,7 +1318,7 @@ fn extend_next_long_word_end(cx: &mut Context) { extend_word_impl(cx, movement::move_next_long_word_end) } -/// Separate branch to find_char designed only for <ret> char. +/// Separate branch to find_char designed only for `<ret>` char. // // This is necessary because the one document can have different line endings inside. And we // cannot predict what character to find when <ret> is pressed. On the current line it can be `lf` @@ -5606,12 +5606,18 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) { }; // These `usize`s cannot underflow because selection ranges cannot overlap. - // Once the MSRV is 1.66.0 (mixed_integer_ops is stabilized), we can use checked - // arithmetic to assert this. - let anchor = (to as isize + offset - deleted_len as isize) as usize; + let anchor = to + .checked_add_signed(offset) + .expect("Selection ranges cannot overlap") + .checked_sub(deleted_len) + .expect("Selection ranges cannot overlap"); let new_range = Range::new(anchor, anchor + output_len).with_direction(range.direction()); ranges.push(new_range); - offset = offset + output_len as isize - deleted_len as isize; + offset = offset + .checked_add_unsigned(output_len) + .expect("Selection ranges cannot overlap") + .checked_sub_unsigned(deleted_len) + .expect("Selection ranges cannot overlap"); changes.push((from, to, Some(output))); } |