mirror of
https://github.com/openai/codex.git
synced 2026-11-05 20:10:33 +00:00
Preserve whitespace in startup pastes
This commit is contained in:
@@ -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),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user