Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Prefill rename prompt with current thread name (#18057)

Eric Traut9c56e89e4f7b
diff --git a/codex-rs/tui/src/bottom_pane/custom_prompt_view.rs b/codex-rs/tui/src/bottom_pane/custom_prompt_view.rs
index e9f0ee697f..753aae51c7 100644
--- a/codex-rs/tui/src/bottom_pane/custom_prompt_view.rs
+++ b/codex-rs/tui/src/bottom_pane/custom_prompt_view.rs
@@ -41,15 +41,22 @@ impl CustomPromptView {
pub(crate) fn new(
title: String,
placeholder: String,
+ initial_text: String,
context_label: Option<String>,
on_submit: PromptSubmitted,
) -> Self {
+ let mut textarea = TextArea::new();
+ if !initial_text.is_empty() {
+ textarea.set_text_clearing_elements(&initial_text);
+ textarea.set_cursor(initial_text.len());
+ }
+
Self {
title,
placeholder,
context_label,
on_submit,
- textarea: TextArea::new(),
+ textarea,
textarea_state: RefCell::new(TextAreaState::default()),
complete: false,
}
diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs
index 9471c29ca6..de71efb9d8 100644
--- a/codex-rs/tui/src/chatwidget.rs
+++ b/codex-rs/tui/src/chatwidget.rs
@@ -5279,11 +5279,8 @@ impl ChatWidget {
fn show_rename_prompt(&mut self) {
let tx = self.app_event_tx.clone();
- let has_name = self
- .thread_name
- .as_ref()
- .is_some_and(|name| !name.is_empty());
- let title = if has_name {
+ let existing_name = self.thread_name.as_deref().filter(|name| !name.is_empty());
+ let title = if existing_name.is_some() {
"Rename thread"
} else {
"Name thread"
@@ -5291,6 +5288,7 @@ impl ChatWidget {
let view = CustomPromptView::new(
title.to_string(),
"Type a name and press Enter".to_string(),
+ /*initial_text*/ existing_name.unwrap_or_default().to_string(),
/*context_label*/ None,
Box::new(move |name: String| {
let Some(name) = crate::legacy_core::util::normalize_thread_name(&name) else {
@@ -10599,6 +10597,7 @@ impl ChatWidget {
let view = CustomPromptView::new(
"Custom review instructions".to_string(),
"Type instructions and press Enter".to_string(),
+ /*initial_text*/ String::new(),
/*context_label*/ None,
Box::new(move |prompt: String| {
let trimmed = prompt.trim().to_string();
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__slash_rename_prefilled_prompt.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__slash_rename_prefilled_prompt.snap
new file mode 100644
index 0000000000..f1eb0d223b
--- /dev/null
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__slash_rename_prefilled_prompt.snap
@@ -0,0 +1,10 @@
+---
+source: tui/src/chatwidget/tests/slash_commands.rs
+assertion_line: 135
+expression: popup
+---
+▌ Rename thread
+▌
+▌ Current project title
+
+Press enter to confirm or esc to go back
diff --git a/codex-rs/tui/src/chatwidget/tests/slash_commands.rs b/codex-rs/tui/src/chatwidget/tests/slash_commands.rs
index 7174b28b80..0c6b9be8e6 100644
--- a/codex-rs/tui/src/chatwidget/tests/slash_commands.rs
+++ b/codex-rs/tui/src/chatwidget/tests/slash_commands.rs
@@ -124,6 +124,39 @@ async fn inline_slash_command_is_available_from_local_recall_after_dispatch() {
assert_eq!(chat.bottom_pane.composer_text(), "/rename Better title");
}
+#[tokio::test]
+async fn slash_rename_prefills_existing_thread_name() {
+ let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
+ chat.thread_name = Some("Current project title".to_string());
+
+ chat.dispatch_command(SlashCommand::Rename);
+
+ let popup = render_bottom_popup(&chat, /*width*/ 80);
+ assert_chatwidget_snapshot!("slash_rename_prefilled_prompt", popup);
+
+ chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
+
+ assert_matches!(
+ rx.try_recv(),
+ Ok(AppEvent::CodexOp(Op::SetThreadName { name })) if name == "Current project title"
+ );
+}
+
+#[tokio::test]
+async fn slash_rename_without_existing_thread_name_starts_empty() {
+ let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
+
+ chat.dispatch_command(SlashCommand::Rename);
+
+ let popup = render_bottom_popup(&chat, /*width*/ 80);
+ assert!(popup.contains("Name thread"));
+ assert!(popup.contains("Type a name and press Enter"));
+
+ chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
+
+ assert_matches!(rx.try_recv(), Err(TryRecvError::Empty));
+}
+
#[tokio::test]
async fn usage_error_slash_command_is_available_from_local_recall() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(Some("gpt-5.3-codex")).await;