From 4c18e632ce6e3a2f959d70942b89e1dd4d0466fa Mon Sep 17 00:00:00 2001 From: jay Date: Wed, 8 Jul 2026 11:21:29 -0700 Subject: [PATCH] Move reset picker cancel action to the end --- ...tests__rate_limit_reset_picker_narrow.snap | 6 +- ..._tests__rate_limit_reset_popup_states.snap | 6 +- codex-rs/tui/src/chatwidget/tests/usage.rs | 6 +- codex-rs/tui/src/chatwidget/usage.rs | 65 +++++++++---------- 4 files changed, 39 insertions(+), 44 deletions(-) diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__rate_limit_reset_picker_narrow.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__rate_limit_reset_picker_narrow.snap index d64823547f..ccfcbf4677 100644 --- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__rate_limit_reset_picker_narrow.snap +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__rate_limit_reset_picker_narrow.snap @@ -5,9 +5,9 @@ expression: "render_bottom_popup(&chat, 44)" Usage limit resets 2 usage limit resets available. -› 1. Cancel - 2. Full reset Expires 09:39 on 18 Jun +› 1. Full reset Expires 09:39 on 18 Jun 2026. - 3. Full reset Does not expire. + 2. Full reset Does not expire. + 3. Cancel Press enter to confirm or esc to go back diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__rate_limit_reset_popup_states.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__rate_limit_reset_popup_states.snap index b018313adc..9f92c0674f 100644 --- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__rate_limit_reset_popup_states.snap +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__rate_limit_reset_popup_states.snap @@ -12,9 +12,9 @@ expression: "states.join(\"\\n---\\n\")" Usage limit resets 2 usage limit resets available. -› 1. Cancel - 2. Full reset (Weekly + 5 hr) Expires 09:39 on 18 Jun 2026. - 3. Full reset (Weekly + 5 hr) Expires 08:59 on 27 Jun 2026. +› 1. Full reset (Weekly + 5 hr) Expires 09:39 on 18 Jun 2026. + 2. Full reset (Weekly + 5 hr) Expires 08:59 on 27 Jun 2026. + 3. Cancel Press enter to confirm or esc to go back --- diff --git a/codex-rs/tui/src/chatwidget/tests/usage.rs b/codex-rs/tui/src/chatwidget/tests/usage.rs index cdbbcca4ad..06bc142670 100644 --- a/codex-rs/tui/src/chatwidget/tests/usage.rs +++ b/codex-rs/tui/src/chatwidget/tests/usage.rs @@ -441,7 +441,6 @@ async fn rate_limit_reset_confirmation_uses_backend_copy_snapshot() { vec![credit], )), )); - chat.handle_key_event(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)); chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)); let Ok(AppEvent::OpenRateLimitResetConfirmation { @@ -495,7 +494,6 @@ async fn rate_limit_reset_confirmation_no_and_escape_return_to_picker() { Vec::new(), Ok(reset_credits(/*available_count*/ 1)), )); - chat.handle_key_event(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)); let picker = render_bottom_popup(&chat, /*width*/ 80); chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)); chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)); @@ -533,7 +531,6 @@ async fn rejected_reset_confirmation_rearms_its_picker_row() { )), )); - chat.handle_key_event(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)); chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)); chat.handle_key_event(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)); chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)); @@ -594,7 +591,7 @@ async fn rate_limit_reset_picker_starts_with_soonest_expiries_and_keeps_all_rows ); assert!(!rendered.contains("Full reset ("), "{rendered}"); - for _ in 0..9 { + for _ in 0..8 { chat.handle_key_event(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)); } chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)); @@ -629,7 +626,6 @@ async fn rate_limit_reset_confirmation_can_use_reset() { )), )); - chat.handle_key_event(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)); chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)); show_rate_limit_reset_confirmation_from_event(&mut chat, &mut rx); assert!(rx.try_recv().is_err()); diff --git a/codex-rs/tui/src/chatwidget/usage.rs b/codex-rs/tui/src/chatwidget/usage.rs index 7f8b7a8074..fdb0131108 100644 --- a/codex-rs/tui/src/chatwidget/usage.rs +++ b/codex-rs/tui/src/chatwidget/usage.rs @@ -169,42 +169,41 @@ impl ChatWidget { picker_request_id: u64, reset_credits: &RateLimitResetCreditsSummary, ) -> SelectionViewParams { - let mut items = vec![SelectionItem { + let mut items = reset_credit_options(reset_credits) + .into_iter() + .map(|option| { + let confirmation_gate = Arc::new(AtomicBool::new(true)); + let credit_id = option.credit_id; + let reset_title = option.name.clone(); + let reset_detail = option.detail; + let reset_description = option.description; + let picker_description = reset_detail + .clone() + .unwrap_or_else(|| reset_description.clone()); + SelectionItem { + name: option.name, + description: Some(picker_description), + actions: vec![Box::new(move |tx| { + if confirmation_gate.swap(false, Ordering::AcqRel) { + tx.send(AppEvent::OpenRateLimitResetConfirmation { + picker_request_id, + confirmation_gate: confirmation_gate.clone(), + credit_id: credit_id.clone(), + reset_title: reset_title.clone(), + reset_detail: reset_detail.clone(), + reset_description: reset_description.clone(), + }); + } + })], + ..Default::default() + } + }) + .collect::>(); + items.push(SelectionItem { name: "Cancel".to_string(), dismiss_on_select: true, ..Default::default() - }]; - items.extend( - reset_credit_options(reset_credits) - .into_iter() - .map(|option| { - let confirmation_gate = Arc::new(AtomicBool::new(true)); - let credit_id = option.credit_id; - let reset_title = option.name.clone(); - let reset_detail = option.detail; - let reset_description = option.description; - let picker_description = reset_detail - .clone() - .unwrap_or_else(|| reset_description.clone()); - SelectionItem { - name: option.name, - description: Some(picker_description), - actions: vec![Box::new(move |tx| { - if confirmation_gate.swap(false, Ordering::AcqRel) { - tx.send(AppEvent::OpenRateLimitResetConfirmation { - picker_request_id, - confirmation_gate: confirmation_gate.clone(), - credit_id: credit_id.clone(), - reset_title: reset_title.clone(), - reset_detail: reset_detail.clone(), - reset_description: reset_description.clone(), - }); - } - })], - ..Default::default() - } - }), - ); + }); SelectionViewParams { view_id: Some(RATE_LIMIT_RESET_VIEW_ID), title: Some("Usage limit resets".to_string()),