diff options
author | Kirawi | 2021-09-10 15:12:26 +0000 |
---|---|---|
committer | GitHub | 2021-09-10 15:12:26 +0000 |
commit | 987d8e6dd66d65c2503cc81a3b9ea8787435839a (patch) | |
tree | ea04c075e2e6bdff623ad45d47dc13be9720c8eb /helix-term/src | |
parent | 94abc52b3b0929f399cea14e1efcf2c1d0a31ad8 (diff) |
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
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index a7a71576..f9ebb801 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3462,7 +3462,14 @@ 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); + // Only compiled once. + #[allow(clippy::trivial_regex)] + static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\r\n|\r|\n").unwrap()); + let mut values = values + .iter() + .map(|value| 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); |