Preserve whitespace in startup pastes

This commit is contained in:
Charlie Marsh
2026-07-05 20:48:55 -04:00
parent 2662e58f97
commit 944dcb100d
2 changed files with 16 additions and 4 deletions
+13 -2
View File
@@ -73,8 +73,19 @@ impl StartupInputBuffer {
}
pub(super) fn push_text(&mut self, text: &str) {
for ch in text.chars().filter(|ch| !ch.is_control()) {
self.push_char(ch);
let mut chars = text.chars().peekable();
while let Some(ch) = chars.next() {
match ch {
'\r' => {
if chars.peek() == Some(&'\n') {
chars.next();
}
self.push_char('\n');
}
'\n' | '\t' => self.push_char(ch),
ch if !ch.is_control() => self.push_char(ch),
_ => {}
}
}
}
+3 -2
View File
@@ -16,8 +16,9 @@ fn startup_input_keeps_text_without_replaying_actions() {
Event::Key(KeyEvent::new(KeyCode::Char('I'), KeyModifiers::SHIFT)),
Event::Key(KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL)),
Event::Key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)),
Event::Key(KeyEvent::new(KeyCode::Tab, KeyModifiers::NONE)),
Event::Key(KeyEvent::new(KeyCode::Backspace, KeyModifiers::NONE)),
Event::Paste("ello\nworld".to_string()),
Event::Paste("ello\r\n\tworld".to_string()),
Event::Key(KeyEvent::new_with_kind(
KeyCode::Char('!'),
KeyModifiers::NONE,
@@ -27,7 +28,7 @@ fn startup_input_keeps_text_without_replaying_actions() {
input.handle_event(event);
}
assert_eq!(input.into_text(), Some("helloworld".to_string()));
assert_eq!(input.into_text(), Some("hello\n\tworld".to_string()));
}
#[test]