From d1ecb251ea740358f47669e938ecd62082f8b3e3 Mon Sep 17 00:00:00 2001 From: Hunter Bown Date: Sat, 23 May 2026 21:24:52 -0500 Subject: [PATCH] fix(tui): preserve CR paste line breaks --- crates/tui/src/tui/app.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/tui/src/tui/app.rs b/crates/tui/src/tui/app.rs index ce0498e7..a6de0622 100644 --- a/crates/tui/src/tui/app.rs +++ b/crates/tui/src/tui/app.rs @@ -395,7 +395,7 @@ fn remove_char_at(text: &mut String, char_index: usize) -> bool { fn normalize_paste_text(text: &str) -> String { if text.contains('\r') { - text.replace("\r\n", "\n").replace('\r', "") + text.replace("\r\n", "\n").replace('\r', "\n") } else { text.to_string() } @@ -5786,11 +5786,24 @@ mod tests { app.insert_paste_text("a\r\nb\rc"); - assert_eq!(app.input, "xa\nbc"); - assert_eq!(app.cursor_position, "xa\nbc".chars().count()); + assert_eq!(app.input, "xa\nb\nc"); + assert_eq!(app.cursor_position, "xa\nb\nc".chars().count()); assert!(!app.paste_burst.is_active()); } + #[test] + fn bracketed_paste_preserves_bare_carriage_return_line_breaks() { + let mut app = App::new(test_options(false), &Config::default()); + + app.insert_paste_text("alpha\r indented\r# literal heading\r- literal list"); + + assert_eq!( + app.input, + "alpha\n indented\n# literal heading\n- literal list" + ); + assert_eq!(app.cursor_position, app.input.chars().count()); + } + #[test] fn enter_during_active_paste_burst_appends_newline_to_buffer_not_submit() { // #1073: when chars are still being assembled into a paste burst and