Persist slash-command popup dismissal (#32858)

## What changed

- Make `Esc` dismiss the slash-command popup immediately without changing the draft or interrupting a running task.
- Keep the popup closed while the first-line command token is unchanged, and reopen it after the token is edited.

## Testing

- Cover dismissal while idle and while a task is running.
- Add a snapshot confirming that the dismissed popup remains hidden.

GitOrigin-RevId: f0ee84af080181e8d92c435f474ded1c8cb5b457
This commit is contained in:
Charlie Marsh authored and copyberry committed 2026-07-13 19:08:11 +00:00
1 parent abbb8c569c
commit bbe93d3e5f
5 files changed
+62 -23

No files matched your search

@@ -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>,
@@ -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";