Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove special handling of line ending characters in selection replacement #10786

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use helix_core::{
history::UndoKind,
increment, indent,
indent::IndentStyle,
line_ending::{get_line_ending_of_str, line_end_char_index, str_is_line_ending},
line_ending::{get_line_ending_of_str, line_end_char_index},
match_brackets,
movement::{self, move_vertically_visual, Direction},
object, pos_at_coords,
Expand Down Expand Up @@ -1596,14 +1596,7 @@ fn replace(cx: &mut Context) {
if !range.is_empty() {
let text: String =
RopeGraphemes::new(doc.text().slice(range.from()..range.to()))
.map(|g| {
let cow: Cow<str> = g.into();
if str_is_line_ending(&cow) {
cow
} else {
ch.into()
}
})
.map(|_| -> Cow<str> { ch.into() })
.collect();

(range.from(), range.to(), Some(text.into()))
chrispyles marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
14 changes: 14 additions & 0 deletions helix-term/tests/test/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,19 @@ fn foo() {
))
.await?;

test((
indoc! {"\
#[a|]#
b
c
d
e
f
"},
"4xs\\n<ret>r,",
chrispyles marked this conversation as resolved.
Show resolved Hide resolved
"a#[,|]#b#(,|)#c#(,|)#d#(,|)#e\nf\n",
))
.await?;

Ok(())
}
Loading