Discard unsaved experimental feature edits on cancel (#61694)

## What changed

Close the experimental features popup without saving pending edits when the user presses `Esc`, `Ctrl+C`, or a remapped cancel key. Keep saving on the accept action (`Enter` by default), and update the footer from `esc save/close` to `esc cancel`.

## Testing

Update tests to assert that cancellation discards toggles without emitting save events, including after a failed write and with a remapped cancel key. Refresh popup snapshots for the new hint.

GitOrigin-RevId: d7640edaeca1db371a7087312179a001d7528b9a
This commit is contained in:
Eric Traut
2026-11-15 21:11:16 +00:00
committed by copyberry
parent 03cb329415
commit 1a2a9299c1
15 changed files with 22 additions and 49 deletions
@@ -366,13 +366,6 @@ impl BottomPaneView for ExperimentalFeaturesView {
}
fn on_ctrl_c(&mut self) -> CancellationEvent {
// After an attempted save, cancellation must remain possible even if the
// server rejects retries immediately. Explicit accept retries dirty keys.
if !self.unconfirmed.is_empty() {
self.save_special_controls();
} else {
self.save_changes();
}
self.complete = true;
CancellationEvent::Handled
}
@@ -457,7 +450,7 @@ fn experimental_popup_hint_line(keymap: &ListKeymap) -> Line<'static> {
if let Some(cancel) = keymap.primary_hint(ListAction::Cancel) {
spans.push(" · ".into());
spans.extend(cancel.spans());
spans.push(" save/close".into());
spans.push(" cancel".into());
}
Line::from(spans)
}
@@ -191,14 +191,10 @@ fn experimental_features_discovery_preserves_server_order_and_accepts_new_keys()
.send(Err("Persistent write rejection".to_string()))
.unwrap();
view.pre_draw_tick(Instant::now());
// Cancel saves new special edits without retrying the failed generic write.
// Cancel discards new edits without retrying the failed write.
view.features[2].enabled = true;
view.handle_key_event(KeyEvent::from(KeyCode::Esc));
assert!(view.is_complete());
assert!(
matches!(app_rx.try_recv().unwrap(), AppEvent::UpdateFeatureFlags { updates }
if updates == vec![(Feature::PreventIdleSleep, true)])
);
assert!(app_rx.try_recv().is_err());
}
@@ -239,6 +235,7 @@ fn experimental_features_empty_error_and_cancel_remain_usable() {
let mut buffer = Buffer::empty(area);
view.render(area, &mut buffer);
insta::assert_snapshot!(snapshot, buffer_text(&buffer));
view.toggle_selected();
view.on_ctrl_c();
assert!(view.is_complete());
assert!(app_rx.try_recv().is_err());
@@ -12,4 +12,4 @@ expression: buffer_text(&buffer)
consumer accounts in /analytics.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
@@ -11,4 +11,4 @@ expression: buffer_text(&buffer)
› [x] Server network_proxy Description supplied by the server.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
@@ -12,4 +12,4 @@ expression: buffer_text(&buffer)
No experimental features available for now
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
@@ -15,7 +15,7 @@ width=68
[ ] Last feature Keep this choice visible.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
width=69
@@ -30,7 +30,7 @@ width=69
[ ] Last feature Keep this choice visible.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
width=70
@@ -44,7 +44,7 @@ width=70
[ ] Last feature Keep this choice visible.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
width=71
@@ -57,7 +57,7 @@ width=71
[ ] Last feature Keep this choice visible.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
width=72
@@ -70,4 +70,4 @@ width=72
[ ] Last feature Keep this choice visible.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
@@ -13,4 +13,4 @@ expression: buffer_text(&buffer)
PATH.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
@@ -12,4 +12,4 @@ expression: buffer_text(&buffer)
requests.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
@@ -13,4 +13,4 @@ expression: buffer_text(&buffer)
[x] Server prevent_idle_sleep Description supplied by the server.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
@@ -13,4 +13,4 @@ expression: buffer_text(&buffer)
No experimental features available for now
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
@@ -14,4 +14,4 @@ expression: popup
running a thread.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
@@ -12,4 +12,4 @@ expression: "render_bottom_popup(&chat, 80)"
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
@@ -14,4 +14,4 @@ expression: popup
[ ] Voice conversations Talk with Codex using /voice.
space toggle · enter save · esc save/close
space toggle · enter save · esc cancel
@@ -10,4 +10,4 @@ expression: popup
› [x] Shell tool Allow the model to run shell commands.
space toggle · ⌃x enter save · esc save/close
space toggle · ⌃x enter save · esc cancel
@@ -3150,7 +3150,7 @@ async fn experimental_features_popup_snapshot() {
}
#[tokio::test]
async fn experimental_features_toggle_saves_on_exit() {
async fn experimental_features_cancel_discards_toggle() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
let mut keymap = crate::keymap::RuntimeKeymap::defaults().list;
@@ -3179,25 +3179,8 @@ async fn experimental_features_toggle_saves_on_exit() {
);
chat.handle_key_event(KeyEvent::new(KeyCode::F(2), KeyModifiers::NONE));
assert!(
!chat.has_active_view(),
"remapped cancel must save and close"
);
let mut updates = None;
while let Ok(event) = rx.try_recv() {
if let AppEvent::SaveExperimentalFeatures {
updates: event_updates,
..
} = event
{
updates = Some(event_updates);
break;
}
}
let updates = updates.expect("expected SaveExperimentalFeatures event");
assert_eq!(updates, vec![(expected_feature.key().to_string(), true)]);
assert!(!chat.has_active_view(), "remapped cancel must close");
assert!(rx.try_recv().is_err(), "cancel must discard the toggle");
}
#[tokio::test]