Skip to content

Commit

Permalink
Don't replace newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
vv9k committed Jun 7, 2021
1 parent b1653a5 commit b90ef9c
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,23 +429,32 @@ pub fn replace(cx: &mut Context) {
..
} = event
{
let text = Tendril::from_char(ch);

let (view, doc) = cx.current();
let ranges: Vec<_> = doc
.selection(view.id)
.ranges()
.iter()
.map(|r| r.anchor..=r.head)
.collect();

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(),
to,
Some(text.repeat(to - range.from()).into()),
)
});
for range in ranges {
let text: String = doc
.text()
.slice(range)
.chars()
.map(|c| if c == '\n' { '\n' } else { ch })
.collect();

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(), to, Some(text.as_str().into()))
});

doc.apply(&transaction, view.id);
doc.append_changes_to_history(view.id);
doc.apply(&transaction, view.id);
doc.append_changes_to_history(view.id);
}
}
})
}
Expand Down

0 comments on commit b90ef9c

Please sign in to comment.