From 167b4f0e254638165191a6162f264cefb4bced79 Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Thu, 11 Sep 2025 11:45:17 -0700 Subject: [PATCH] Clear composer on fork (#3445) Fixes this image --- codex-rs/tui/src/app_backtrack.rs | 2 +- codex-rs/tui/src/bottom_pane/chat_composer.rs | 4 ++++ codex-rs/tui/src/chatwidget.rs | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/codex-rs/tui/src/app_backtrack.rs b/codex-rs/tui/src/app_backtrack.rs index 4445c939..d1765c19 100644 --- a/codex-rs/tui/src/app_backtrack.rs +++ b/codex-rs/tui/src/app_backtrack.rs @@ -335,7 +335,7 @@ impl App { self.trim_transcript_for_backtrack(drop_count); self.render_transcript_once(tui); if !prefill.is_empty() { - self.chat_widget.insert_str(prefill); + self.chat_widget.set_composer_text(prefill.to_string()); } tui.frame_requester().schedule_frame(); } diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs index c94144bf..14094bad 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs @@ -243,6 +243,10 @@ impl ChatComposer { /// Replace the entire composer content with `text` and reset cursor. pub(crate) fn set_text_content(&mut self, text: String) { + // Clear any existing content, placeholders, and attachments first. + self.textarea.set_text(""); + self.pending_pastes.clear(); + self.attached_images.clear(); self.textarea.set_text(&text); self.textarea.set_cursor(0); self.sync_command_popup(); diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index 1ccfddea..7f9ea765 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -1316,6 +1316,11 @@ impl ChatWidget { self.bottom_pane.insert_str(text); } + /// Replace the composer content with the provided text and reset cursor. + pub(crate) fn set_composer_text(&mut self, text: String) { + self.bottom_pane.set_composer_text(text); + } + pub(crate) fn show_esc_backtrack_hint(&mut self) { self.bottom_pane.show_esc_backtrack_hint(); }