aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorWojciech Kępka2021-06-07 17:03:44 +0000
committerBlaž Hrastnik2021-06-08 08:23:38 +0000
commit2e4a338944d31e77b4db5dd7d578aacedef3256f (patch)
treed43305f9379d609579f791f3a2492295f461a6c2 /helix-term/src
parent9c83a98469927e310fcd24ad8fcf13a719609d5f (diff)
Add bounds checks to replace
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index d34afda4..94e1af2d 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -472,10 +472,12 @@ pub fn replace(cx: &mut Context) {
let transaction =
Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
+ let max_to = doc.text().len_chars().saturating_sub(1);
+ let to = std::cmp::min(max_to, range.to() + 1);
(
range.from(),
- range.to() + 1,
- Some(text.repeat(range.to() - range.from() + 1).into()),
+ to,
+ Some(text.repeat(to - range.from()).into()),
)
});