Skip to content

Commit 4979374

Browse files
genkijoshka-oai
authored andcommitted
Fix IME submissions dropping leading digits (openai#4359)
- ensure paste burst flush preserves ASCII characters before IME commits - add regression test covering digit followed by Japanese text submission Fixes openai#4356 Co-authored-by: Josh McKinney <[email protected]>
1 parent 19bdf69 commit 4979374

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

codex-rs/tui/src/bottom_pane/chat_composer.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,35 @@ mod tests {
20692069
}
20702070
}
20712071

2072+
#[test]
2073+
fn ascii_prefix_survives_non_ascii_followup() {
2074+
use crossterm::event::KeyCode;
2075+
use crossterm::event::KeyEvent;
2076+
use crossterm::event::KeyModifiers;
2077+
2078+
let (tx, _rx) = unbounded_channel::<AppEvent>();
2079+
let sender = AppEventSender::new(tx);
2080+
let mut composer = ChatComposer::new(
2081+
true,
2082+
sender,
2083+
false,
2084+
"Ask Codex to do anything".to_string(),
2085+
false,
2086+
);
2087+
2088+
let _ = composer.handle_key_event(KeyEvent::new(KeyCode::Char('1'), KeyModifiers::NONE));
2089+
assert!(composer.is_in_paste_burst());
2090+
2091+
let _ = composer.handle_key_event(KeyEvent::new(KeyCode::Char('あ'), KeyModifiers::NONE));
2092+
2093+
let (result, _) =
2094+
composer.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
2095+
match result {
2096+
InputResult::Submitted(text) => assert_eq!(text, "1あ"),
2097+
_ => panic!("expected Submitted"),
2098+
}
2099+
}
2100+
20722101
#[test]
20732102
fn handle_paste_small_inserts_text() {
20742103
use crossterm::event::KeyCode;

codex-rs/tui/src/bottom_pane/paste_burst.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,15 @@ impl PasteBurst {
198198

199199
/// Before applying modified/non-char input: flush buffered burst immediately.
200200
pub fn flush_before_modified_input(&mut self) -> Option<String> {
201-
if self.is_active() {
202-
self.active = false;
203-
Some(std::mem::take(&mut self.buffer))
204-
} else {
205-
None
201+
if !self.is_active() {
202+
return None;
203+
}
204+
self.active = false;
205+
let mut out = std::mem::take(&mut self.buffer);
206+
if let Some((ch, _at)) = self.pending_first_char.take() {
207+
out.push(ch);
206208
}
209+
Some(out)
207210
}
208211

209212
/// Clear only the timing window and any pending first-char.

0 commit comments

Comments
 (0)