Skip to content

Commit

Permalink
Convert clipboard line ending to document line ending when pasting (#716
Browse files Browse the repository at this point in the history
)

* convert a paste's line-ending to the current doc's line-ending

* move paste regex into paste_impl
  • Loading branch information
kirawi authored Sep 10, 2021
1 parent 94abc52 commit 987d8e6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 987d8e6

Please sign in to comment.