From ec745235a95df0004e14069b79689814104c199c Mon Sep 17 00:00:00 2001 From: JJ Liebig Date: Thu, 3 Sep 2026 19:03:47 +0200 Subject: fix(windows): preserve LF paste order (#3582) refs #3172 --- src/platform/mod.rs | 9 +++++++++ src/platform/windows.rs | 12 ++++++++++++ 2 files changed, 21 insertions(+) (limited to 'src/platform') diff --git a/src/platform/mod.rs b/src/platform/mod.rs index b831e120..f15c71ef 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -39,6 +39,15 @@ pub(crate) fn apply_pane_runtime_marker(command: &mut portable_pty::CommandBuild apply_pane_runtime_marker_platform(command); } +pub(crate) fn prepare_paste_text_for_pty(text: String) -> String { + prepare_paste_text_for_pty_platform(text) +} + +#[cfg(not(windows))] +fn prepare_paste_text_for_pty_platform(text: String) -> String { + text +} + #[cfg(not(windows))] pub(crate) fn terminal_title_for_presentation(title: &str) -> &str { title diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 890c24ca..8d370964 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -134,6 +134,10 @@ pub(crate) fn terminal_title_for_presentation(title: &str) -> &str { title.strip_prefix("Administrator: ").unwrap_or(title) } +pub(crate) fn prepare_paste_text_for_pty_platform(text: String) -> String { + text.replace("\r\n", "\n").replace('\n', "\r\n") +} + /// Resolves against the current foreground layout because asynchronous console /// records do not retain the layout that was active when the key was pressed. pub(crate) fn resolve_base_printable_key(vk: u16, scan: u16) -> Option { @@ -2598,6 +2602,14 @@ mod tests { AllocConsole, FreeConsole, GetConsoleProcessList, GetConsoleWindow, }; + #[test] + fn paste_text_uses_windows_line_endings() { + assert_eq!( + super::prepare_paste_text_for_pty_platform("one\ntwo\r\nthree\rfour".to_owned()), + "one\r\ntwo\r\nthree\rfour" + ); + } + #[test] fn private_remote_directory_supports_long_paths() { let base = std::env::temp_dir().join(format!( -- cgit v1.2.3