From dc5182de992fb884c8eb72b4db380366c92d6438 Mon Sep 17 00:00:00 2001 From: Chris Pyles <cpyles@berkeley.edu> Date: Fri, 17 May 2024 19:41:03 -0700 Subject: [PATCH] Remove special-casing of line ending characters in selection replacement --- helix-core/src/match_brackets.rs | 4 ++-- helix-term/src/commands.rs | 11 ++--------- helix-term/tests/test/commands.rs | 14 ++++++++++++++ helix-term/tests/test/commands/movement.rs | 16 ++++++++++++++++ 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/helix-core/src/match_brackets.rs b/helix-core/src/match_brackets.rs index 0e08c4898c2d2..5351b56dcae23 100644 --- a/helix-core/src/match_brackets.rs +++ b/helix-core/src/match_brackets.rs @@ -87,13 +87,13 @@ fn find_pair( (as_char(doc, &open), as_char(doc, &close)) { if PAIRS.contains(&(open, close)) { - if start_pos == pos_ { + if end_pos == pos_ { return Some(start_pos); } // We return the end char if the cursor is either on the start char // or at some arbitrary position between start and end char. - if traverse_parents || end_pos == pos_ { + if traverse_parents || start_pos == pos_ { return Some(end_pos); } } diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 7be2ea0954c90..c3e7aeac904c9 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, @@ -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())) diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 1c5c6196b5c6a..379770580a166 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 + "}, + "4xs\\n<ret>r,", + "a#[,|]#b#(,|)#c#(,|)#d#(,|)#e\nf\n", + )) + .await?; + Ok(()) } diff --git a/helix-term/tests/test/commands/movement.rs b/helix-term/tests/test/commands/movement.rs index ed6984288ec46..5868fa49433c7 100644 --- a/helix-term/tests/test/commands/movement.rs +++ b/helix-term/tests/test/commands/movement.rs @@ -895,6 +895,22 @@ async fn match_bracket() -> anyhow::Result<()> { } "##}, ), + // named node with 2 or more children + ( + indoc! {r##" + use a::#[{|]# + b::{c, d, e, f, g}, + h, i, j, k, l, m, n, + }; + "##}, + "mm", + indoc! {r##" + use a::{ + b::{c, d, e, f, g}, + h, i, j, k, l, m, n, + #[}|]#; + "##}, + ), ]; let python_tests = vec![