on master help sign in
Don't replace newlines
c349cebWojciech Kępka
helix-term/src/commands.rs+8−7
@@ -466,19 +466,20 @@ pub fn replace(cx: &mut Context) {
466 ..
466 ..
467 } = event
467 } = event
468 {
468 {
469− let text = Tendril::from_char(ch);
470−
471 let (view, doc) = cx.current();
469 let (view, doc) = cx.current();
472
470
473 let transaction =
471 let transaction =
474 Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
472 Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
475 let max_to = doc.text().len_chars().saturating_sub(1);
473 let max_to = doc.text().len_chars().saturating_sub(1);
476 let to = std::cmp::min(max_to, range.to() + 1);
474 let to = std::cmp::min(max_to, range.to() + 1);
477− (
475+ let text: String = doc
476+ .text()
478− range.from(),
477+ .slice(range.from()..to)
479− to,
478+ .chars()
479+ .map(|c| if c == '\n' { '\n' } else { ch })
480+ .collect();
481+
480− Some(text.repeat(to - range.from()).into()),
482+ (range.from(), to, Some(text.as_str().into()))
481− )
482 });
483 });
483
484
484 doc.apply(&transaction, view.id);
485 doc.apply(&transaction, view.id);