Skip to content

Commit

Permalink
Remove special handling of line ending characters in selection replac…
Browse files Browse the repository at this point in the history
…ement (helix-editor#10786)

* Remove special-casing of line ending characters in selection replacement

* Refactor line ending handling and integration test to address code review comments
  • Loading branch information
chrispyles authored and Schuyler Mortimer committed Jul 10, 2024
1 parent 9a9a7f3 commit 6418c53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
16 changes: 4 additions & 12 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 @@ -1605,19 +1605,11 @@ fn replace(cx: &mut Context) {
if let Some(ch) = ch {
let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
if !range.is_empty() {
let text: String =
let text: Tendril =
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(|_g| ch)
.collect();

(range.from(), range.to(), Some(text.into()))
(range.from(), range.to(), Some(text))
} else {
// No change.
(range.from(), range.to(), None)
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
"},
"s\\n<ret>r,",
"a#[,|]#b#(,|)#c#(,|)#d#(,|)#e\nf\n",
))
.await?;

Ok(())
}

0 comments on commit 6418c53

Please sign in to comment.