on master help sign in
Don't replace newlines
commitc349ceb61f7af9e90db7a58d2305da239157ae63 authorWojciech Kępka <wojtek.kepka@protonmail.com> dateMon 7 Jun 2021, 21:28 (5 years ago) parent2e4a338
1 file changed+8−7
helix-term/src/commands.rs+8−7
helix-term/src/commands.rs+8−7
@@ -466,19 +466,20 @@ pub fn replace(cx: &mut Context) {
466466 ..
467467 } = event
468468 {
469− let text = Tendril::from_char(ch);
470−
471469 let (view, doc) = cx.current();
472470
473471 let transaction =
474472 Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
475473 let max_to = doc.text().len_chars().saturating_sub(1);
476474 let to = std::cmp::min(max_to, range.to() + 1);
477− (
478− range.from(),
479− to,
480− Some(text.repeat(to - range.from()).into()),
481− )
475+ let text: String = doc
476+ .text()
477+ .slice(range.from()..to)
478+ .chars()
479+ .map(|c| if c == '\n' { '\n' } else { ch })
480+ .collect();
481+
482+ (range.from(), to, Some(text.as_str().into()))
482483 });
483484
484485 doc.apply(&transaction, view.id);