From d6b04a4b8d6b7507fb474c0f5b163e4e2664b831 Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Wed, 8 Sep 2021 12:57:09 -0400 Subject: [PATCH 1/2] convert a paste's line-ending to the current doc's line-ending --- helix-term/src/commands.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 2fbed6b3f888..ced1d96bbb71 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3415,6 +3415,10 @@ enum Paste { After, } +// Only compiled once. +#[allow(clippy::trivial_regex)] +static PASTE_LINE_ENDING_REGEX: Lazy = Lazy::new(|| Regex::new(r"\r\n|\r|\n").unwrap()); + fn paste_impl( values: &[String], doc: &mut Document, @@ -3433,7 +3437,11 @@ fn paste_impl( .iter() .any(|value| get_line_ending_of_str(value).is_some()); - let mut values = values.iter().cloned().map(Tendril::from).chain(repeat); + let mut values = values + .iter() + .map(|value| PASTE_LINE_ENDING_REGEX.replace_all(value, doc.line_ending.as_str())) + .map(|value| Tendril::from(value.as_ref())) + .chain(repeat); let text = doc.text(); let selection = doc.selection(view.id); From 1648f65daabb2bc9a3bdd8bb80761259d0b07c54 Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Fri, 10 Sep 2021 10:22:54 -0400 Subject: [PATCH 2/2] move paste regex into paste_impl --- helix-term/src/commands.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index ced1d96bbb71..511830b01d00 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3415,10 +3415,6 @@ enum Paste { After, } -// Only compiled once. -#[allow(clippy::trivial_regex)] -static PASTE_LINE_ENDING_REGEX: Lazy = Lazy::new(|| Regex::new(r"\r\n|\r|\n").unwrap()); - fn paste_impl( values: &[String], doc: &mut Document, @@ -3437,9 +3433,12 @@ fn paste_impl( .iter() .any(|value| get_line_ending_of_str(value).is_some()); + // Only compiled once. + #[allow(clippy::trivial_regex)] + static REGEX: Lazy = Lazy::new(|| Regex::new(r"\r\n|\r|\n").unwrap()); let mut values = values .iter() - .map(|value| PASTE_LINE_ENDING_REGEX.replace_all(value, doc.line_ending.as_str())) + .map(|value| REGEX.replace_all(value, doc.line_ending.as_str())) .map(|value| Tendril::from(value.as_ref())) .chain(repeat);