on master help sign in
Convert clipboard line ending to document line ending when pasting (#716)

* convert a paste's line-ending to the current doc's line-ending * move paste regex into paste_impl

commit987d8e6dd66d65c2503cc81a3b9ea8787435839a authorKirawi <67773714+kirawi@users.noreply.github.com> dateFri 10 Sep 2021, 11:12 (5 years ago) parent94abc52
1 file changed+8−1
helix-term/src/commands.rs+8−1
helix-term/src/commands.rs+8−1
@@ -3462,7 +3462,14 @@ fn paste_impl(
34623462 .iter()
34633463 .any(|value| get_line_ending_of_str(value).is_some());
34643464
3465− let mut values = values.iter().cloned().map(Tendril::from).chain(repeat);
3465+ // Only compiled once.
3466+ #[allow(clippy::trivial_regex)]
3467+ static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\r\n|\r|\n").unwrap());
3468+ let mut values = values
3469+ .iter()
3470+ .map(|value| REGEX.replace_all(value, doc.line_ending.as_str()))
3471+ .map(|value| Tendril::from(value.as_ref()))
3472+ .chain(repeat);
34663473
34673474 let text = doc.text();
34683475 let selection = doc.selection(view.id);