From 49c33f79a75f32b5dea49804db29b65683ed5a69 Mon Sep 17 00:00:00 2001 From: Chris Pyles <40970945+chrispyles@users.noreply.github.com> Date: Mon, 10 Jun 2024 08:07:43 -0700 Subject: [PATCH] Remove special handling of line ending characters in selection replacement (#10786) * Remove special-casing of line ending characters in selection replacement * Refactor line ending handling and integration test to address code review comments --- helix-term/src/commands.rs | 16 ++++------------ helix-term/tests/test/commands.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 673e737e4605b..3938adb57b89c 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -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, @@ -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 = 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) diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 1c5c6196b5c6a..7f41a2219acbf 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -722,5 +722,19 @@ fn foo() { )) .await?; + test(( + indoc! {"\ + #[a + b + c + d + e|]# + f + "}, + "s\\nr,", + "a#[,|]#b#(,|)#c#(,|)#d#(,|)#e\nf\n", + )) + .await?; + Ok(()) }