Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert clipboard line ending to document line ending when pasting #716

Merged
merged 2 commits into from
Sep 10, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3415,6 +3415,10 @@ enum Paste {
After,
}

// Only compiled once.
#[allow(clippy::trivial_regex)]
static PASTE_LINE_ENDING_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\r\n|\r|\n").unwrap());
kirawi marked this conversation as resolved.
Show resolved Hide resolved

fn paste_impl(
values: &[String],
doc: &mut Document,
Expand All @@ -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()))
kirawi marked this conversation as resolved.
Show resolved Hide resolved
.map(|value| Tendril::from(value.as_ref()))
.chain(repeat);

let text = doc.text();
let selection = doc.selection(view.id);
Expand Down