diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs index 4ca11b7723..522e14bdcf 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs @@ -311,7 +311,7 @@ //! - Unmodified Tab joins detected bursts, including short Unicode prefixes, before popup dispatch. //! Expired bursts are flushed first so manual Tab keeps its normal shortcut behavior. //! - [`ChatComposer::flush_paste_burst_if_due`]/[`ChatComposer::handle_paste_burst_flush`]: called -//! from UI ticks to integrate a pending burst via [`ChatComposer::apply_paste`] or insert a +//! from UI ticks to display a burst while preserving its Enter deadline, or to insert a //! held single character. Explicit paste events (terminal or clipboard) use //! [`ChatComposer::handle_paste`], which first commits buffered typing before classifying the //! pasted text. This preserves the order when a paste arrives before the next burst-flush tick; @@ -1833,9 +1833,7 @@ impl ChatComposer { /// Flush buffered typing before clearing so cancellation preserves the complete draft in history. pub(crate) fn clear_for_ctrl_c(&mut self) -> Option { - if let Some(pasted) = self.draft.paste_burst.flush_before_modified_input() { - self.apply_paste(pasted); - } + self.flush_pending_input(); if self.is_empty() { return None; } @@ -1971,8 +1969,7 @@ impl ChatComposer { /// /// Call this from a UI tick to turn paste-burst transient state into explicit textarea edits: /// - /// - If a burst times out, integrate it via [`Self::apply_paste`]. Its key events have already - /// been classified; [`Self::handle_paste`] classifies explicit terminal pastes instead. + /// - If a burst times out, display the text while preserving its Enter deadline. /// - If only the first ASCII char was held (flicker suppression) and no burst followed, emit it /// as normal typed input. /// @@ -3693,14 +3690,16 @@ impl ChatComposer { { return (InputResult::None, true); } - if self.queue_keys.is_pressed(key_event) - && (self.is_task_running || self.queue_submissions || !self.is_bang_shell_command()) - { - return self.handle_submission(self.is_task_running || self.queue_submissions); - } - - if self.submit_keys.is_pressed(key_event) { - return self.handle_submission(self.queue_submissions); + let queue = self.queue_keys.is_pressed(key_event) + && (self.is_task_running || self.queue_submissions || !self.is_bang_shell_command()); + if queue || self.submit_keys.is_pressed(key_event) { + // Raw paste tabs were handled before popup dispatch. Only a plain Enter + // reaching submission can still be a trailing pasted newline. + if key_event.code != KeyCode::Enter || !key_event.modifiers.is_empty() { + self.flush_pending_input(); + } + return self + .handle_submission(self.queue_submissions || (queue && self.is_task_running)); } if let KeyEvent { @@ -6403,20 +6402,17 @@ mod tests { assert_eq!(composer.footer_mode(), FooterMode::ComposerEmpty); } - #[test] - fn clear_for_ctrl_c_records_cleared_draft() { - let (tx, _rx) = unbounded_channel::(); - let sender = AppEventSender::new(tx); - let mut composer = ChatComposer::new( - /*has_input_focus*/ true, - sender, - /*enhanced_keys_supported*/ false, - "Ask Codex to do anything".to_string(), - /*disable_paste_burst*/ false, - ); - - composer.set_text_content("draft text".to_string(), Vec::new(), Vec::new()); + #[tokio::test(start_paused = true)] + async fn clear_for_ctrl_c_records_cleared_draft() { + let (mut composer, _rx) = new_test_composer(); + for ch in "draft text".chars() { + composer.handle_key_event(KeyEvent::from(KeyCode::Char(ch))); + } + tokio::time::advance(PasteBurst::recommended_active_flush_delay()).await; + assert!(composer.flush_paste_burst_if_due()); assert_eq!(composer.clear_for_ctrl_c(), Some("draft text".to_string())); + composer.handle_key_event(KeyEvent::from(KeyCode::Enter)); + composer.flush_pending_paste_burst(); assert!(composer.is_empty()); assert_eq!( diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/blockquote_paste_tests.rs b/codex-rs/tui/src/bottom_pane/chat_composer/blockquote_paste_tests.rs index 74e4a2a445..14e684f719 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer/blockquote_paste_tests.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer/blockquote_paste_tests.rs @@ -10,6 +10,8 @@ fn blockquote_paste_continues_current_line_prefix() { for (draft, pasted, expected) in [ ("> ", "first\nsecond", "> first\n> second\n\n"), ("> ", "first\n", "> first\n\n"), + ("> first", "\n", "> first\n"), + ("> first", "\n\t", "> first\n\t"), ("intro\n> ", "α\r\n\r\nβ\r", "intro\n> α\n> \n> β\n\n"), ( "> existing ", diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/paste_input.rs b/codex-rs/tui/src/bottom_pane/chat_composer/paste_input.rs index 568ca846d4..ebac200a34 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer/paste_input.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer/paste_input.rs @@ -170,21 +170,11 @@ impl ChatComposer { } pub(in crate::bottom_pane) fn has_paste_window(&self, now: Instant) -> bool { + // Short IME prefixes are inserted directly. Require multiple rapid characters + // before intercepting submit so Enter after a lone IME commit still submits. + let burst = &self.draft.paste_burst; !self.draft.disable_paste_burst - && self - .draft - .paste_burst - .newline_should_insert_instead_of_submit(now) - } - - /// Display flushed text without losing the window for its trailing paste keys. - pub(in crate::bottom_pane) fn flush_handoff_paste(&mut self, now: Instant) -> bool { - let deadline = self.paste_handoff_deadline(); - let flushed = self.handle_paste_burst_flush(now); - if flushed && let Some(deadline) = deadline.filter(|deadline| *deadline >= now) { - self.draft.paste_burst.preserve_window_until(deadline); - } - flushed + && (burst.in_burst_window(now) || burst.recent_plain_char_count(now) >= 2) } /// Enable or disable paste-burst handling. @@ -217,7 +207,7 @@ impl ChatComposer { /// Applies any due `PasteBurst` flush at time `now`. /// /// Converts [`PasteBurst::flush_if_due`] results into concrete textarea mutations. - /// Buffered keys have already been classified; paste results use [`Self::apply_paste`]. + /// Buffered keys have already been classified. Keep their Enter suppression deadline. /// /// Callers: /// @@ -227,7 +217,8 @@ impl ChatComposer { pub(super) fn handle_paste_burst_flush(&mut self, now: Instant) -> bool { match self.draft.paste_burst.flush_if_due(now) { FlushResult::Paste(pasted) => { - self.apply_paste(pasted); + // A trailing Enter may still belong to this unmarked paste. + self.apply_paste_with_shell_prefix(pasted, ShellPrefixHandling::Interpret); if !self.draft.textarea.is_vim_enabled() { self.finish_edit(); } @@ -249,6 +240,12 @@ impl ChatComposer { } } + /// An explicit paste or a forced flush ends the previous burst. + pub(super) fn apply_paste(&mut self, pasted: String) -> bool { + self.draft.paste_burst.clear_after_explicit_paste(); + self.apply_paste_with_shell_prefix(pasted, ShellPrefixHandling::Interpret) + } + /// Integrate pasted text into the composer. /// /// Both input paths integrate their text here: @@ -266,12 +263,6 @@ impl ChatComposer { /// - Otherwise, if the paste looks like an image path, attaches the image and inserts a /// trailing space so the user can keep typing naturally. /// - Otherwise, inserts the pasted text directly into the textarea. - /// - /// Composer edits clear paste-burst Enter suppression and sync popups. - pub(super) fn apply_paste(&mut self, pasted: String) -> bool { - self.apply_paste_with_shell_prefix(pasted, ShellPrefixHandling::Interpret) - } - pub(super) fn apply_paste_with_shell_prefix( &mut self, pasted: String, @@ -297,12 +288,10 @@ impl ChatComposer { let is_blockquote = self.config.blockquote_paste_enabled && !self.is_bang_shell_command() && current_line.starts_with("> ") - && pasted.contains('\n'); + && pasted.contains('\n') + && pasted.contains(|ch: char| !matches!(ch, '\n' | '\t')); let pasted = if is_blockquote { - let pasted = pasted - .strip_suffix('\n') - .filter(|pasted| !pasted.is_empty()) - .unwrap_or(pasted.as_ref()); + let pasted = pasted.strip_suffix('\n').unwrap_or(pasted.as_ref()); std::borrow::Cow::Owned(pasted.replace('\n', "\n> ")) } else { pasted @@ -347,7 +336,6 @@ impl ChatComposer { let textarea = &mut self.draft.textarea; textarea.insert_str_at(textarea.cursor(), "\n\n"); } - self.draft.paste_burst.clear_after_explicit_paste(); self.reconcile_deleted_elements(elements_before); self.sync_popups(); if started_edit { @@ -377,12 +365,19 @@ impl ChatComposer { return true; } - // Short non-ASCII prefixes are inserted directly, without a held first character. - if self - .draft - .paste_burst - .direct_insert_newline_should_insert(now) - { + // A trailing pasted newline starts a new buffer so indentation stays with it. + // Tab on its own resumes its shortcut after a flush unless a handoff owns the draft. + let continues_paste = + if self.popups.restricted_input_mode == Some(RestrictedInputMode::DraftHandoff) { + self.draft + .paste_burst + .direct_insert_newline_should_insert(now) + } else if separator == '\n' { + self.has_paste_window(now) + } else { + self.draft.paste_burst.recent_plain_char_count(now) > 0 + }; + if continues_paste { self.draft .paste_burst .begin_with_retro_grabbed(String::new(), now); diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/paste_tests.rs b/codex-rs/tui/src/bottom_pane/chat_composer/paste_tests.rs index 55eb5d0a82..e124639371 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer/paste_tests.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer/paste_tests.rs @@ -1,4 +1,4 @@ -//! Composer paste handling for literal paths and raw tabs. +//! Composer paste handling for literal paths and raw multiline input. use super::tests::new_test_composer; use super::*; @@ -30,6 +30,39 @@ fn pasting_fifo_path_keeps_it_editable() { ); } +#[tokio::test(start_paused = true)] +async fn paste_burst_keeps_newlines_after_short_unicode_and_flushed_lines() { + let (mut composer, _rx) = new_test_composer(); + for ch in "有几个问题:".chars() { + composer.handle_key_event(KeyCode::Char(ch).into()); + } + assert_eq!(composer.current_text(), "有几个问题:"); + for line in ["- first", "- second"] { + let (result, _) = composer.handle_key_event(KeyCode::Enter.into()); + assert_eq!(result, InputResult::None); + assert_eq!( + composer.handle_key_event(KeyCode::Tab.into()).0, + InputResult::None + ); + for ch in line.chars() { + composer.handle_key_event(KeyCode::Char(ch).into()); + } + tokio::time::advance(PasteBurst::recommended_active_flush_delay()).await; + assert!(composer.flush_paste_burst_if_due()); + } + insta::assert_snapshot!(composer.current_text(), @"有几个问题: +\t- first +\t- second"); + + tokio::time::advance(Duration::from_secs(1)).await; + let expected = InputResult::Submitted { + text: composer.current_text(), + text_elements: Vec::new(), + }; + let (result, _) = composer.handle_key_event(KeyCode::Enter.into()); + assert_eq!(result, expected); +} + #[test] fn paste_burst_tabs_preserve_multiline_draft() { for running in [false, true] { diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/reconnect.rs b/codex-rs/tui/src/bottom_pane/chat_composer/reconnect.rs index af268e80a6..13029416e8 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer/reconnect.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer/reconnect.rs @@ -4,7 +4,7 @@ //! Connected unavailable threads retain the empty-prompt agents shortcut. //! Paste Enter handling is shared with normal submission so buffered newlines survive both paths. //! In the draft-only handoff, a recent paste prefix can preserve a raw Enter as a newline. -//! The submit path still requires an established paste before treating Enter as a newline. +//! In an ordinary draft, a lone IME character does not turn Enter into a newline. //! Recovery commands must occupy one line and be visible before the submit key expands pastes. //! Offline draft edits also consume the Astra sparkle opportunity before rendering. @@ -102,33 +102,7 @@ impl ChatComposer { .next() .unwrap_or("") .starts_with('/')); - !in_slash_context && self.append_paste_newline(now) - } - - fn append_paste_newline(&mut self, now: Instant) -> bool { - if self.draft.disable_paste_burst { - return false; - } - if self.draft.paste_burst.is_active() - && self - .draft - .paste_burst - .append_control_char_if_active('\n', now) - { - self.begin_promoted_paste_edit(); - return true; - } - if self - .draft - .paste_burst - .newline_should_insert_instead_of_submit(now) - { - self.draft.textarea.insert_str("\n"); - self.draft.paste_burst.extend_window(now); - return true; - } - - false + !in_slash_context && self.append_recent_paste_separator('\n', now) } pub(crate) fn handle_restricted_key( @@ -140,7 +114,7 @@ impl ChatComposer { if mode == RestrictedInputMode::DraftHandoff { if matches!(key.kind, KeyEventKind::Press | KeyEventKind::Repeat) { let now = tokio::time::Instant::now().into_std(); - self.flush_handoff_paste(now); + self.handle_paste_burst_flush(now); // Completion does not own keys during the handoff. self.popups.active = ActivePopup::None; if self.draft.textarea.wants_vim_search_key(key) { @@ -152,8 +126,7 @@ impl ChatComposer { // newline after a directly inserted prefix, as we do for Tab. let paste_separator = (key.code == KeyCode::Enter && key.modifiers.is_empty() - && (self.append_paste_newline(now) - || self.append_recent_paste_separator('\n', now))) + && self.append_recent_paste_separator('\n', now)) || self.handle_paste_tab(key, now); if !paste_separator && !self.submit_keys.is_pressed(key) diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/reconnect_tests.rs b/codex-rs/tui/src/bottom_pane/chat_composer/reconnect_tests.rs index aae51bdfc4..132ff5b673 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer/reconnect_tests.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer/reconnect_tests.rs @@ -16,7 +16,7 @@ async fn draft_handoff_preserves_newline_after_short_unicode_prefix() { ); } tokio::time::advance(Duration::from_millis(/*millis*/ 100)).await; - composer.flush_handoff_paste(tokio::time::Instant::now().into_std()); + composer.flush_paste_burst_if_due(); composer.handle_restricted_key(KeyCode::Enter.into(), RestrictedInputMode::DraftHandoff); insta::assert_snapshot!(composer.current_text(), @"猫 犬"); diff --git a/codex-rs/tui/src/bottom_pane/chat_composer_enter_tests.rs b/codex-rs/tui/src/bottom_pane/chat_composer_enter_tests.rs index ea059b4100..c707c63dee 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer_enter_tests.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer_enter_tests.rs @@ -9,7 +9,6 @@ use crossterm::event::KeyModifiers; use pretty_assertions::assert_eq; use super::InputResult; -use super::PasteBurst; use super::tests::new_test_composer; use super::tests::snapshot_composer_state_with_width; @@ -34,10 +33,9 @@ fn enter_expires_paste_state_without_a_ui_tick() { assert!(composer.is_in_paste_burst()); assert_eq!(composer.current_text(), ""); - let result = composer.handle_submission_with_time( - /*should_queue*/ false, - now + PasteBurst::recommended_active_flush_delay(), - ); + let expired = composer.paste_handoff_deadline().unwrap() + Duration::from_millis(1); + let result = + composer.handle_submission_with_time(/*should_queue*/ false, expired); let expected = if parent_owned { InputResult::ParentOwnedInputBlocked } else { diff --git a/codex-rs/tui/src/bottom_pane/paste_burst.rs b/codex-rs/tui/src/bottom_pane/paste_burst.rs index 57c855d098..2a268243bf 100644 --- a/codex-rs/tui/src/bottom_pane/paste_burst.rs +++ b/codex-rs/tui/src/bottom_pane/paste_burst.rs @@ -30,8 +30,8 @@ //! - On Enter or Tab, [`PasteBurst::append_control_char_if_active`] promotes a held first character //! into the active buffer before appending the newline or tab and refreshing the idle timeout. //! - On a UI tick, call [`PasteBurst::flush_if_due`]. If it returns [`FlushResult::Typed`], insert -//! that char as normal typing. If it returns [`FlushResult::Paste`], treat the returned string as -//! an explicit paste. +//! that char as normal typing. If it returns [`FlushResult::Paste`], apply the text and preserve +//! the original Enter suppression deadline. //! - Before applying non-text input (arrow keys; Ctrl/Alt shortcuts other than Windows AltGr; //! or Super, Hyper, and Meta modifiers), use //! [`PasteBurst::flush_before_modified_input`] to avoid leaving buffered text "stuck", and then @@ -145,7 +145,7 @@ //! //! - Periodically (e.g. on a UI tick), call [`PasteBurst::flush_if_due`]. //! - [`FlushResult::Typed`]: insert that single char as normal typing. -//! - [`FlushResult::Paste`]: treat the returned string as an explicit paste. +//! - [`FlushResult::Paste`]: apply the text without ending Enter suppression. //! //! - When non-text input is pressed (Ctrl/Alt shortcuts other than Windows AltGr; Super, Hyper, //! and Meta modifiers; arrows; etc.), callers should use @@ -277,13 +277,7 @@ impl PasteBurst { } fn note_plain_char(&mut self, now: Instant) { - match self.last_plain_char_time { - Some(prev) if now.duration_since(prev) <= PASTE_BURST_CHAR_INTERVAL => { - self.consecutive_plain_char_burst = - self.consecutive_plain_char_burst.saturating_add(1) - } - _ => self.consecutive_plain_char_burst = 1, - } + self.consecutive_plain_char_burst = self.recent_plain_char_count(now).saturating_add(1); self.last_plain_char_time = Some(now); } @@ -316,6 +310,8 @@ impl PasteBurst { pub(crate) fn flush_pending(&mut self) -> FlushResult { if self.is_active_internal() { self.active = false; + self.last_plain_char_time = None; + self.consecutive_plain_char_burst = 0; let out = std::mem::take(&mut self.buffer); FlushResult::Paste(out) } else if let Some((ch, _at)) = self.pending_first_char.take() { @@ -347,16 +343,27 @@ impl PasteBurst { /// Decide if Enter should insert a newline (burst context) vs submit. pub fn newline_should_insert_instead_of_submit(&self, now: Instant) -> bool { - let in_burst_window = self.burst_window_until.is_some_and(|until| now <= until); - self.is_active() || in_burst_window + self.is_active() || self.in_burst_window(now) + } + + pub(super) fn in_burst_window(&self, now: Instant) -> bool { + self.burst_window_until.is_some_and(|until| now <= until) } /// Decide if Enter should insert a newline for callers that insert chars immediately. pub fn direct_insert_newline_should_insert(&self, now: Instant) -> bool { - self.newline_should_insert_instead_of_submit(now) - || self - .last_plain_char_time - .is_some_and(|t| now.duration_since(t) <= PASTE_BURST_CHAR_INTERVAL) + self.newline_should_insert_instead_of_submit(now) || self.recent_plain_char_count(now) > 0 + } + + pub(super) fn recent_plain_char_count(&self, now: Instant) -> u16 { + if self + .last_plain_char_time + .is_some_and(|t| now.duration_since(t) <= PASTE_BURST_CHAR_INTERVAL) + { + self.consecutive_plain_char_burst + } else { + 0 + } } /// Keep input in this composer while keys can still belong to its paste. @@ -371,10 +378,6 @@ impl PasteBurst { .max(self.burst_window_until) } - pub(super) fn preserve_window_until(&mut self, deadline: Instant) { - self.burst_window_until = self.burst_window_until.max(Some(deadline)); - } - /// Keep the burst window alive. pub fn extend_window(&mut self, now: Instant) { self.burst_window_until = Some(now + PASTE_ENTER_SUPPRESS_WINDOW); diff --git a/codex-rs/tui/src/bottom_pane/startup.rs b/codex-rs/tui/src/bottom_pane/startup.rs index 1378b19929..7c7df5e644 100644 --- a/codex-rs/tui/src/bottom_pane/startup.rs +++ b/codex-rs/tui/src/bottom_pane/startup.rs @@ -144,8 +144,7 @@ impl BottomPane { } pub(crate) fn flush_handoff_paste_if_due(&mut self) -> bool { - self.composer - .flush_handoff_paste(tokio::time::Instant::now().into_std()) + self.composer.flush_paste_burst_if_due() } /// Preserve buffered composer input before its owner or input mode changes. diff --git a/codex-rs/tui/src/startup_draft_input.rs b/codex-rs/tui/src/startup_draft_input.rs index d28d57512b..1035b4a05c 100644 --- a/codex-rs/tui/src/startup_draft_input.rs +++ b/codex-rs/tui/src/startup_draft_input.rs @@ -48,7 +48,14 @@ impl StartupDraftPump { kind: KeyEventKind::Press | KeyEventKind::Repeat, .. }) if modifiers.is_empty() => { - if started_at.elapsed() <= STARTUP_PASTE_NEWLINE_TIMEOUT { + // Text may still follow a deferred newline, but a fresh Enter + // can confirm the visible draft once its paste window closes. + if started_at.elapsed() <= STARTUP_PASTE_NEWLINE_TIMEOUT + && self + .bottom_pane + .composer_paste_deadline() + .is_none_or(|deadline| Instant::now().into_std() <= deadline) + { newlines.push('\n'); self.pending_paste_newline = Some((Instant::now(), newlines)); return Ok(()); @@ -101,12 +108,9 @@ impl StartupDraftPump { || !self.bottom_pane.is_safe_startup_editor_key(key)) { let text_len = self.bottom_pane.composer_text().len(); - let retained_paste = self.session_action - == super::StartupDraftSessionAction::NewWhileRunning - && !self.bottom_pane.is_in_paste_burst() - && self - .bottom_pane - .has_startup_paste_window(Instant::now().into_std()); + let retained_paste = self + .bottom_pane + .has_startup_paste_window(Instant::now().into_std()); self.bottom_pane.flush_composer_paste_burst(); if retained_paste || self diff --git a/codex-rs/tui/src/startup_draft_submission_tests.rs b/codex-rs/tui/src/startup_draft_submission_tests.rs index 5c232a5f91..d6983d272d 100644 --- a/codex-rs/tui/src/startup_draft_submission_tests.rs +++ b/codex-rs/tui/src/startup_draft_submission_tests.rs @@ -97,15 +97,21 @@ async fn startup_submission_honors_configured_submit_binding() { assert_eq!(pump.into_draft(), draft); } -#[tokio::test] +#[tokio::test(start_paused = true)] async fn startup_submission_accepts_enter_after_paste_ambiguity_expires() { let mut pump = tests::quiet_startup_test_pump(); let mut tui = crate::tui::test_support::make_test_tui().expect("create test terminal"); - pump.bottom_pane.insert_str("pasted draft"); - pump.pending_paste_newline = Some(( - Instant::now() - STARTUP_PASTE_NEWLINE_TIMEOUT - Duration::from_millis(/*millis*/ 1), - "\n".into(), - )); + for ch in "pasted draft".chars() { + pump.handle_event(&mut tui, TuiEvent::Key(KeyEvent::from(KeyCode::Char(ch)))) + .unwrap(); + } + tokio::time::advance(Duration::from_millis(80)).await; + pump.handle_event(&mut tui, TuiEvent::Draw).unwrap(); + assert_eq!(pump.bottom_pane.composer_text(), "pasted draft"); + pump.handle_event(&mut tui, TuiEvent::Key(KeyEvent::from(KeyCode::Enter))) + .expect("defer Enter inside the paste window"); + assert!(!pump.submission_pending); + tokio::time::advance(Duration::from_millis(50)).await; pump.handle_event(&mut tui, TuiEvent::Key(KeyEvent::from(KeyCode::Enter))) .expect("confirm after the ambiguous paste has finished"); assert!(pump.take_submission_intent()); diff --git a/codex-rs/tui/src/startup_draft_tests.rs b/codex-rs/tui/src/startup_draft_tests.rs index 64d2928b17..a74291bd88 100644 --- a/codex-rs/tui/src/startup_draft_tests.rs +++ b/codex-rs/tui/src/startup_draft_tests.rs @@ -550,18 +550,17 @@ fn startup_draft_preserves_multiline_editing_without_submitting() { #[tokio::test(start_paused = true)] async fn startup_draft_preserves_non_bracketed_multiline_pastes_without_submitting() { - let events = "first line\n\nsecond line\nthird line" - .chars() - .map(|character| { - TuiEvent::Key(KeyEvent::new( - if character == '\n' { - KeyCode::Enter - } else { - KeyCode::Char(character) - }, - KeyModifiers::NONE, - )) - }); + let payload = "有几个问题:\n问:\nfirst line\n\nsecond line\nthird line"; + let events = payload.chars().map(|character| { + TuiEvent::Key(KeyEvent::new( + if character == '\n' { + KeyCode::Enter + } else { + KeyCode::Char(character) + }, + KeyModifiers::NONE, + )) + }); let mut pump = startup_test_pump(events); let mut tui = crate::tui::test_support::make_test_tui().expect("create test terminal"); @@ -570,10 +569,7 @@ async fn startup_draft_preserves_non_bracketed_multiline_pastes_without_submitti .expect("preserve multiline non-bracketed paste"); assert!(!pump.submission_pending); - assert_eq!( - pump.bottom_pane.composer_text(), - "first line\n\nsecond line\nthird line" - ); + assert_eq!(pump.bottom_pane.composer_text(), payload); assert!(pump.app_event_rx.try_recv().is_err()); pump.handle_event( @@ -581,10 +577,7 @@ async fn startup_draft_preserves_non_bracketed_multiline_pastes_without_submitti TuiEvent::Key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)), ) .expect("ignore standalone Enter after the paste finishes"); - assert_eq!( - pump.bottom_pane.composer_text(), - "first line\n\nsecond line\nthird line" - ); + assert_eq!(pump.bottom_pane.composer_text(), payload); assert!(pump.app_event_rx.try_recv().is_err()); } diff --git a/codex-rs/tui/tests/suite/worktree_stack.rs b/codex-rs/tui/tests/suite/worktree_stack.rs index c080e5f379..07a34cbddb 100644 --- a/codex-rs/tui/tests/suite/worktree_stack.rs +++ b/codex-rs/tui/tests/suite/worktree_stack.rs @@ -116,7 +116,9 @@ async fn picker_side_worktree_fork_and_cd_run_on_the_production_stack() -> Resul // A trailing bare Escape must not consume the first character of the fresh edit. terminal.write_input(b"\x1b[27u\x1b[27u\r\x1b[27u\x1b[27u\r\x1b")?; terminal.wait_for_screen("Conversation reverted to this point")?; - terminal.write_input(b" Revised.")?; + // Leave the leading space unmarked to exercise Escape, then explicitly + // end the paste so the next Enter is an unambiguous submit. + terminal.write_input(b" \x1b[200~Revised.\x1b[201~")?; terminal.wait_for_screen("Reply with the marker requested by this test. Revised.")?; let _edited_reply = responses::mount_sse_once_match( &server,