From 389e850ff91a8e7ade1d952923790a2876054db0 Mon Sep 17 00:00:00 2001 From: Charles Cunningham Date: Sat, 31 Jan 2026 20:40:52 -0800 Subject: [PATCH] tui: centralize command drain --- codex-rs/tui/src/bottom_pane/mod.rs | 6 ++++++ codex-rs/tui/src/chatwidget.rs | 25 +++++-------------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/codex-rs/tui/src/bottom_pane/mod.rs b/codex-rs/tui/src/bottom_pane/mod.rs index 7d8c175161..24bb61c62d 100644 --- a/codex-rs/tui/src/bottom_pane/mod.rs +++ b/codex-rs/tui/src/bottom_pane/mod.rs @@ -218,6 +218,12 @@ impl BottomPane { self.composer.take_mention_paths() } + /// Clear pending attachments and mention paths when a command doesn't submit text. + pub(crate) fn drain_pending_submission_state(&mut self) { + let _ = self.take_recent_submission_images_with_placeholders(); + let _ = self.take_mention_paths(); + } + pub fn set_steer_enabled(&mut self, enabled: bool) { self.composer.set_steer_enabled(enabled); } diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index fc4987a0ce..85ab255582 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -2783,10 +2783,7 @@ impl ChatWidget { cmd.command() ); self.add_to_history(history_cell::new_error_event(message)); - let _ = self - .bottom_pane - .take_recent_submission_images_with_placeholders(); - let _ = self.bottom_pane.take_mention_paths(); + self.bottom_pane.drain_pending_submission_state(); self.request_redraw(); return; } @@ -3035,10 +3032,7 @@ impl ChatWidget { cmd.command() ); self.add_to_history(history_cell::new_error_event(message)); - let _ = self - .bottom_pane - .take_recent_submission_images_with_placeholders(); - let _ = self.bottom_pane.take_mention_paths(); + self.bottom_pane.drain_pending_submission_state(); self.request_redraw(); return; } @@ -3055,18 +3049,12 @@ impl ChatWidget { self.request_redraw(); self.app_event_tx .send(AppEvent::CodexOp(Op::SetThreadName { name })); - let _ = self - .bottom_pane - .take_recent_submission_images_with_placeholders(); - let _ = self.bottom_pane.take_mention_paths(); + self.bottom_pane.drain_pending_submission_state(); } SlashCommand::Plan if !trimmed.is_empty() => { self.dispatch_command(cmd); if self.active_mode_kind() != ModeKind::Plan { - let _ = self - .bottom_pane - .take_recent_submission_images_with_placeholders(); - let _ = self.bottom_pane.take_mention_paths(); + self.bottom_pane.drain_pending_submission_state(); return; } let user_message = UserMessage { @@ -3095,10 +3083,7 @@ impl ChatWidget { user_facing_hint: None, }, }); - let _ = self - .bottom_pane - .take_recent_submission_images_with_placeholders(); - let _ = self.bottom_pane.take_mention_paths(); + self.bottom_pane.drain_pending_submission_state(); } _ => self.dispatch_command(cmd), }