on master help sign in
Add bounds checks to replace
2e4a338Wojciech Kępka
helix-term/src/commands.rs+4−2
@@ -472,10 +472,12 @@ pub fn replace(cx: &mut Context) {
472
472
473 let transaction =
473 let transaction =
474 Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
474 Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
475+ let max_to = doc.text().len_chars().saturating_sub(1);
476+ let to = std::cmp::min(max_to, range.to() + 1);
475 (
477 (
476 range.from(),
478 range.from(),
477− range.to() + 1,
479+ to,
478− Some(text.repeat(range.to() - range.from() + 1).into()),
480+ Some(text.repeat(to - range.from()).into()),
479 )
481 )
480 });
482 });
481
483