mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
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:
1 parent
abbb8c569c
commit
bbe93d3e5f
5 files changed
+60
-21
No files matched your search
@@ -33,6 +33,10 @@
|
|||||||
//! Whitespace and atomic-element edges delimit occurrences, while nested sigils do not. This
|
//! 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.
|
//! 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 (↑/↓)
|
//! # History Navigation (↑/↓)
|
||||||
//!
|
//!
|
||||||
//! The Up/Down history path is managed by [`ChatComposerHistory`]. It merges:
|
//! 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
|
/// textarea. This must be called after every modification that can change
|
||||||
/// the text so the popup is shown/updated/hidden as appropriate.
|
/// the text so the popup is shown/updated/hidden as appropriate.
|
||||||
fn sync_command_popup(&mut self, allow: bool) {
|
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 !allow {
|
||||||
if matches!(self.popups.active, ActivePopup::Command(_)) {
|
if matches!(self.popups.active, ActivePopup::Command(_)) {
|
||||||
self.popups.active = ActivePopup::None;
|
self.popups.active = ActivePopup::None;
|
||||||
@@ -3559,9 +3575,6 @@ impl ChatComposer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Determine whether the caret is inside the initial '/name' token on the first line.
|
// 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 cursor = self.draft.textarea.cursor();
|
||||||
let caret_on_first_line = cursor <= first_line_end;
|
let caret_on_first_line = cursor <= first_line_end;
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ fn complete_token_occurrences_before(textarea: &TextArea, token: &str, before: u
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub(super) struct PopupState {
|
pub(super) struct PopupState {
|
||||||
pub(super) active: ActivePopup,
|
pub(super) active: ActivePopup,
|
||||||
|
pub(super) dismissed_command_token: Option<String>,
|
||||||
pub(super) dismissed_file_token: Option<DismissedToken>,
|
pub(super) dismissed_file_token: Option<DismissedToken>,
|
||||||
pub(super) current_file_query: Option<String>,
|
pub(super) current_file_query: Option<String>,
|
||||||
pub(super) dismissed_mention_token: Option<DismissedToken>,
|
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::ByteRange;
|
||||||
use codex_protocol::user_input::TextElement;
|
use codex_protocol::user_input::TextElement;
|
||||||
|
|
||||||
use super::super::footer::esc_hint_mode;
|
|
||||||
use super::super::footer::reset_mode_after_activity;
|
use super::super::footer::reset_mode_after_activity;
|
||||||
use super::ActivePopup;
|
use super::ActivePopup;
|
||||||
use super::ChatComposer;
|
use super::ChatComposer;
|
||||||
@@ -215,14 +214,14 @@ impl ChatComposer {
|
|||||||
return (InputResult::None, true);
|
return (InputResult::None, true);
|
||||||
}
|
}
|
||||||
if key_event.code == KeyCode::Esc {
|
if key_event.code == KeyCode::Esc {
|
||||||
let next_mode = esc_hint_mode(self.footer.mode, self.is_task_running);
|
// Always dismiss the popup without changing the draft.
|
||||||
if next_mode != self.footer.mode {
|
let first_line = self.draft.textarea.text().lines().next().unwrap_or("");
|
||||||
self.footer.mode = next_mode;
|
self.popups.dismissed_command_token =
|
||||||
|
command_popup_filter_text(first_line, /*cursor*/ 0);
|
||||||
|
self.popups.active = ActivePopup::None;
|
||||||
return (InputResult::None, true);
|
return (InputResult::None, true);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
self.footer.mode = reset_mode_after_activity(self.footer.mode);
|
self.footer.mode = reset_mode_after_activity(self.footer.mode);
|
||||||
}
|
|
||||||
let ActivePopup::Command(popup) = &mut self.popups.active else {
|
let ActivePopup::Command(popup) = &mut self.popups.active else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
@@ -251,13 +250,6 @@ impl ChatComposer {
|
|||||||
popup.move_down();
|
popup.move_down();
|
||||||
(InputResult::None, true)
|
(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 {
|
KeyEvent {
|
||||||
code: KeyCode::Tab, ..
|
code: KeyCode::Tab, ..
|
||||||
} => {
|
} => {
|
||||||
@@ -604,6 +596,17 @@ mod tests {
|
|||||||
composer_with_text_at_cursor(&format!("{prefix}{draft}"), prefix.len())
|
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]
|
#[test]
|
||||||
fn slash_completion_preserves_existing_draft_tail_for_inline_arg_commands() {
|
fn slash_completion_preserves_existing_draft_tail_for_inline_arg_commands() {
|
||||||
let draft = "view the diff";
|
let draft = "view the diff";
|
||||||
|
|||||||
@@ -2666,7 +2666,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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_raw, mut rx) = unbounded_channel::<AppEvent>();
|
||||||
let tx = AppEventSender::new(tx_raw);
|
let tx = AppEventSender::new(tx_raw);
|
||||||
let mut pane = BottomPane::new(BottomPaneParams {
|
let mut pane = BottomPane::new(BottomPaneParams {
|
||||||
@@ -2682,11 +2682,12 @@ mod tests {
|
|||||||
|
|
||||||
pane.set_task_running(/*running*/ true);
|
pane.set_task_running(/*running*/ true);
|
||||||
|
|
||||||
// Repro: a running task + slash-command popup + Esc should not interrupt the task.
|
// Repro: a running task + slash-command popup + Esc should dismiss the popup without
|
||||||
pane.insert_str("/");
|
// interrupting the task.
|
||||||
|
pane.insert_str("/rev");
|
||||||
assert!(
|
assert!(
|
||||||
pane.composer.popup_active(),
|
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));
|
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"
|
"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]
|
#[test]
|
||||||
|
|||||||
+10
@@ -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
|
||||||
Reference in new issue
Block a user