Preserve pending Effects toggles across save refreshes (#53496)

## Why

Saving an Effects preference refreshes the picker. When users toggle repeatedly before saves finish, that refresh can discard newer choices and cause subsequent toggles to use stale values.

## What changed

- Update Effects checkboxes immediately and track pending saves per row, preserving newer choices when an earlier save takes effect.
- Preserve pending Composer stars choices while Animations disables the row, and clear pending state on a regular panel refresh.
- Use the shared list toggle handling for Effects, including Space support, while giving configured key bindings precedence over Space toggling.

## Testing

Add regression tests for repeated toggles across save refreshes, pending Composer stars choices while disabled, clearing pending state, and a Space cancel binding taking precedence over toggling. Update the Effects picker snapshot.

GitOrigin-RevId: 847dcc2dfd40448c7adc56c8c40879db28b1fc39
This commit is contained in:
Felipe Coury
2026-10-12 22:44:06 +00:00
committed by copyberry
parent 4a93bd249a
commit 92caad7828
9 changed files with 344 additions and 44 deletions
+7 -2
View File
@@ -102,8 +102,13 @@ impl App {
} else {
None
};
self.chat_widget
.refresh_config_panel(notice.map(str::to_string));
let notice = notice.map(str::to_string);
if effective {
self.chat_widget
.refresh_config_panel_after_effective_save(notice, preference);
} else {
self.chat_widget.refresh_config_panel(notice);
}
tui.frame_requester().schedule_frame();
}
}
+122 -14
View File
@@ -11,6 +11,26 @@ use crate::config_panel::ConfigEditorHandoff;
use crate::local_settings::LocalSettings;
use codex_protocol::config_types::TrustLevel;
use pretty_assertions::assert_eq;
use tokio::sync::mpsc::UnboundedReceiver;
fn open_effects_editor(app: &mut App) {
let handoff = ConfigEditorHandoff::new(
ConfigEditor::Effects,
crate::key_hint::plain(KeyCode::Enter),
);
handoff.mark_activation_inactive();
app.chat_widget.open_config_editor(
handoff,
crate::config_panel::ResumeCurrentAvailability::Available,
);
}
fn next_config_preference(rx: &mut UnboundedReceiver<AppEvent>) -> Result<ConfigPreference> {
let AppEvent::SaveConfigPreference(preference) = rx.try_recv()? else {
panic!("expected config preference save");
};
Ok(preference)
}
#[tokio::test]
async fn config_toggle_save_uses_host_config_and_applies_live_while_offline() -> Result<()> {
@@ -124,32 +144,120 @@ async fn config_toggle_save_uses_host_config_and_applies_live_while_offline() ->
}
#[tokio::test]
async fn effects_editor_refreshes_after_animation_save() -> Result<()> {
async fn effects_editor_refresh_preserves_pending_toggles() -> Result<()> {
let (mut app, mut rx, _ops) = crate::app::tests::make_test_app_with_channels().await;
let mut tui = crate::tui::test_support::make_test_tui()?;
app.local_settings.tui.animations = false;
app.chat_widget.local_settings.tui.animations = false;
app.chat_widget.config_panel_tui.animations = false;
let handoff = ConfigEditorHandoff::new(
ConfigEditor::Effects,
crate::key_hint::plain(KeyCode::Enter),
);
handoff.mark_activation_inactive();
app.chat_widget.open_config_editor(
handoff,
crate::config_panel::ResumeCurrentAvailability::Available,
);
open_effects_editor(&mut app);
app.chat_widget.handle_key_event(KeyCode::Enter.into());
let AppEvent::SaveConfigPreference(preference) = rx.try_recv()? else {
panic!("expected animation save");
};
app.save_config_preference(&mut tui, preference).await;
app.chat_widget.handle_key_event(KeyCode::Enter.into());
let first_preference = next_config_preference(&mut rx)?;
app.save_config_preference(&mut tui, first_preference).await;
insta::assert_snapshot!(
"effects_picker_after_animation_save",
render_bottom_popup(&app.chat_widget, /*width*/ 80)
);
app.chat_widget.handle_key_event(KeyCode::Enter.into());
let second_preference = next_config_preference(&mut rx)?;
app.save_config_preference(&mut tui, second_preference)
.await;
let third_preference = next_config_preference(&mut rx)?;
assert_eq!(
third_preference,
ConfigPreference::Toggle {
setting: ConfigToggle::Animations,
enabled: true,
}
);
app.save_config_preference(&mut tui, third_preference).await;
assert!(app.chat_widget.config_panel_tui.animations);
Ok(())
}
#[tokio::test]
async fn effects_editor_preserves_pending_stars_while_disabled() -> Result<()> {
let (mut app, mut rx, _ops) = crate::app::tests::make_test_app_with_channels().await;
let mut tui = crate::tui::test_support::make_test_tui()?;
app.local_settings.tui.animations = true;
app.local_settings.tui.effects.starfield = true;
app.chat_widget.local_settings.tui.animations = true;
app.chat_widget.local_settings.tui.effects.starfield = true;
app.chat_widget.config_panel_tui.animations = true;
app.chat_widget.config_panel_tui.effects.starfield = true;
open_effects_editor(&mut app);
for shortcut in ['1', '2', '2'] {
app.chat_widget
.handle_key_event(KeyCode::Char(shortcut).into());
}
let animations_off = next_config_preference(&mut rx)?;
assert_eq!(
animations_off,
ConfigPreference::Toggle {
setting: ConfigToggle::Animations,
enabled: false,
}
);
app.save_config_preference(&mut tui, animations_off).await;
app.chat_widget.handle_key_event(KeyCode::Char('1').into());
for _ in 0..3 {
let preference = next_config_preference(&mut rx)?;
app.save_config_preference(&mut tui, preference).await;
}
assert_eq!(
(
app.chat_widget.config_panel_tui.animations,
app.chat_widget.config_panel_tui.effects.starfield,
),
(true, true),
);
app.chat_widget.handle_key_event(KeyCode::Char('2').into());
assert_eq!(
next_config_preference(&mut rx)?,
ConfigPreference::Toggle {
setting: ConfigToggle::ComposerStars,
enabled: false,
}
);
Ok(())
}
#[tokio::test]
async fn effects_editor_reset_clears_pending_toggle_state() -> Result<()> {
let (mut app, mut rx, _ops) = crate::app::tests::make_test_app_with_channels().await;
let mut tui = crate::tui::test_support::make_test_tui()?;
app.local_settings.tui.animations = true;
app.local_settings.tui.effects.starfield = true;
app.chat_widget.local_settings.tui.animations = true;
app.chat_widget.local_settings.tui.effects.starfield = true;
app.chat_widget.config_panel_tui.animations = true;
app.chat_widget.config_panel_tui.effects.starfield = true;
open_effects_editor(&mut app);
app.chat_widget.handle_key_event(KeyCode::Char('1').into());
app.chat_widget.handle_key_event(KeyCode::Char('2').into());
let _animations_off = next_config_preference(&mut rx)?;
let stars_off = next_config_preference(&mut rx)?;
app.chat_widget.refresh_config_panel(/*notice*/ None);
app.save_config_preference(&mut tui, stars_off).await;
assert!(!app.chat_widget.config_panel_tui.effects.starfield);
app.chat_widget.handle_key_event(KeyCode::Char('2').into());
assert_eq!(
next_config_preference(&mut rx)?,
ConfigPreference::Toggle {
setting: ConfigToggle::ComposerStars,
enabled: true,
}
);
Ok(())
}
@@ -6,8 +6,8 @@ expression: "render_bottom_popup(&app.chat_widget, 80)"
Configure visual effects
› 1. [x] Animations Animate the welcome screen, working indicator, and
transitions
2. [x] Composer stars Show stars briefly for new Astra tasks
› 1. [ ] Animations Animate the welcome screen, working
indicator, and transitions
[-] Composer stars (disabled) Turn on Animations to show Astra task stars
enter toggle · esc back