Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Persist slash-command popup dismissal (#32858)

Charlie Marshbbe93d3e5f22
diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs
index bd7b963e2b..4b3f6f1650 100644
--- a/codex-rs/tui/src/bottom_pane/chat_composer.rs
+++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs
@@ -33,6 +33,10 @@
//! Whitespace and atomic-element edges delimit occurrences, while nested sigils do not. This
//! preserves dismissal across offset-only edits without suppressing a later identical token.
//!
+//! Slash-command dismissal is tracked separately. Pressing `Esc` while the command popup is active
+//! records the first-line `/name` token and keeps the popup closed while that token is unchanged.
+//! Editing the command token clears the dismissal and allows the popup to reopen.
+//!
//! # History Navigation (↑/↓)
//!
//! The Up/Down history path is managed by [`ChatComposerHistory`]. It merges:
@@ -3552,6 +3556,18 @@ impl ChatComposer {
/// textarea. This must be called after every modification that can change
/// the text so the popup is shown/updated/hidden as appropriate.
fn sync_command_popup(&mut self, allow: bool) {
+ let text = self.draft.textarea.text();
+ let first_line_end = text.find('\n').unwrap_or(text.len());
+ let first_line = &text[..first_line_end];
+ // Keep an explicitly dismissed popup closed until the command token changes.
+ let command_token = slash_input::command_popup_filter_text(first_line, /*cursor*/ 0);
+ if let Some(command_token) = command_token.as_deref()
+ && self.popups.dismissed_command_token.as_deref() == Some(command_token)
+ {
+ return;
+ }
+ self.popups.dismissed_command_token = None;
+
if !allow {
if matches!(self.popups.active, ActivePopup::Command(_)) {
self.popups.active = ActivePopup::None;
@@ -3559,9 +3575,6 @@ impl ChatComposer {
return;
}
// Determine whether the caret is inside the initial '/name' token on the first line.
- let text = self.draft.textarea.text();
- let first_line_end = text.find('\n').unwrap_or(text.len());
- let first_line = &text[..first_line_end];
let cursor = self.draft.textarea.cursor();
let caret_on_first_line = cursor <= first_line_end;
diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/popup_state.rs b/codex-rs/tui/src/bottom_pane/chat_composer/popup_state.rs
index 29a216cd1e..2f97ecda52 100644
--- a/codex-rs/tui/src/bottom_pane/chat_composer/popup_state.rs
+++ b/codex-rs/tui/src/bottom_pane/chat_composer/popup_state.rs
@@ -89,6 +89,7 @@ fn complete_token_occurrences_before(textarea: &TextArea, token: &str, before: u
#[derive(Default)]
pub(super) struct PopupState {
pub(super) active: ActivePopup,
+ pub(super) dismissed_command_token: Option<String>,
pub(super) dismissed_file_token: Option<DismissedToken>,
pub(super) current_file_query: Option<String>,
pub(super) dismissed_mention_token: Option<DismissedToken>,
diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/slash_input.rs b/codex-rs/tui/src/bottom_pane/chat_composer/slash_input.rs
index 721b92acc8..623a1a6bc5 100644
--- a/codex-rs/tui/src/bottom_pane/chat_composer/slash_input.rs
+++ b/codex-rs/tui/src/bottom_pane/chat_composer/slash_input.rs
@@ -19,7 +19,6 @@ use crate::slash_command::SlashCommand;
use codex_protocol::user_input::ByteRange;
use codex_protocol::user_input::TextElement;
-use super::super::footer::esc_hint_mode;
use super::super::footer::reset_mode_after_activity;
use super::ActivePopup;
use super::ChatComposer;
@@ -215,14 +214,14 @@ impl ChatComposer {
return (InputResult::None, true);
}
if key_event.code == KeyCode::Esc {
- let next_mode = esc_hint_mode(self.footer.mode, self.is_task_running);
- if next_mode != self.footer.mode {
- self.footer.mode = next_mode;
- return (InputResult::None, true);
- }
- } else {
- self.footer.mode = reset_mode_after_activity(self.footer.mode);
+ // Always dismiss the popup without changing the draft.
+ let first_line = self.draft.textarea.text().lines().next().unwrap_or("");
+ self.popups.dismissed_command_token =
+ command_popup_filter_text(first_line, /*cursor*/ 0);
+ self.popups.active = ActivePopup::None;
+ return (InputResult::None, true);
}
+ self.footer.mode = reset_mode_after_activity(self.footer.mode);
let ActivePopup::Command(popup) = &mut self.popups.active else {
unreachable!();
};
@@ -251,13 +250,6 @@ impl ChatComposer {
popup.move_down();
(InputResult::None, true)
}
- KeyEvent {
- code: KeyCode::Esc, ..
- } => {
- // Dismiss the slash popup; keep the current input untouched.
- self.popups.active = ActivePopup::None;
- (InputResult::None, true)
- }
KeyEvent {
code: KeyCode::Tab, ..
} => {
@@ -604,6 +596,17 @@ mod tests {
composer_with_text_at_cursor(&format!("{prefix}{draft}"), prefix.len())
}
+ #[test]
+ fn esc_dismisses_slash_popup_while_idle() {
+ let mut composer = composer_with_text_at_cursor("/rev", "/rev".len());
+ assert!(composer.popup_active());
+
+ assert_eq!(press(&mut composer, KeyCode::Esc), InputResult::None);
+
+ assert!(!composer.popup_active());
+ assert_eq!(composer.draft.textarea.text(), "/rev");
+ }
+
#[test]
fn slash_completion_preserves_existing_draft_tail_for_inline_arg_commands() {
let draft = "view the diff";
diff --git a/codex-rs/tui/src/bottom_pane/mod.rs b/codex-rs/tui/src/bottom_pane/mod.rs
index ad30dedf5a..484016c3d6 100644
--- a/codex-rs/tui/src/bottom_pane/mod.rs
+++ b/codex-rs/tui/src/bottom_pane/mod.rs
@@ -2666,7 +2666,7 @@ mod tests {
}
#[test]
- fn esc_with_slash_command_popup_does_not_interrupt_task() {
+ fn esc_dismisses_slash_command_popup_without_interrupting_task() {
let (tx_raw, mut rx) = unbounded_channel::<AppEvent>();
let tx = AppEventSender::new(tx_raw);
let mut pane = BottomPane::new(BottomPaneParams {
@@ -2682,11 +2682,12 @@ mod tests {
pane.set_task_running(/*running*/ true);
- // Repro: a running task + slash-command popup + Esc should not interrupt the task.
- pane.insert_str("/");
+ // Repro: a running task + slash-command popup + Esc should dismiss the popup without
+ // interrupting the task.
+ pane.insert_str("/rev");
assert!(
pane.composer.popup_active(),
- "expected command popup after typing `/`"
+ "expected command popup after typing `/rev`"
);
pane.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
@@ -2697,7 +2698,18 @@ mod tests {
"expected Esc to not send Op::Interrupt while command popup is active"
);
}
- assert_eq!(pane.composer_text(), "/");
+ assert!(!pane.composer.popup_active());
+ assert_eq!(pane.composer_text(), "/rev");
+
+ let width = 60;
+ let area = Rect::new(0, 0, width, pane.desired_height(width));
+ assert_snapshot!(
+ "slash_command_popup_dismissed",
+ render_snapshot(&pane, area)
+ );
+
+ pane.insert_str("i");
+ assert!(pane.composer.popup_active());
}
#[test]
diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__tests__slash_command_popup_dismissed.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__tests__slash_command_popup_dismissed.snap
new file mode 100644
index 0000000000..2eae5af3d3
--- /dev/null
+++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__tests__slash_command_popup_dismissed.snap
@@ -0,0 +1,10 @@
+---
+source: tui/src/bottom_pane/mod.rs
+expression: "render_snapshot(&pane, area)"
+---
+• Working (0s • esc to interrupt)
+
+
+› /rev
+
+ tab to queue message 100% context left