on master help sign in
Convert clipboard line ending to document line ending when pasting (#716)
987d8e6Kirawi
helix-term/src/commands.rs+8−1
@@ -3462,7 +3462,14 @@ fn paste_impl(
3462 .iter()
3462 .iter()
3463 .any(|value| get_line_ending_of_str(value).is_some());
3463 .any(|value| get_line_ending_of_str(value).is_some());
3464
3464
3465+ // Only compiled once.
3466+ #[allow(clippy::trivial_regex)]
3467+ static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\r\n|\r|\n").unwrap());
3465− let mut values = values.iter().cloned().map(Tendril::from).chain(repeat);
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);
3466
3473
3467 let text = doc.text();
3474 let text = doc.text();
3468 let selection = doc.selection(view.id);
3475 let selection = doc.selection(view.id);