Skip to content

Commit 55def60

Browse files
committed
2 parents e1f1d5c + ef31aeb commit 55def60

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

src-rust/crates/tui/src/settings_screen.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ pub struct SettingsScreen {
7676
impl SettingsScreen {
7777
pub fn new() -> Self {
7878
let settings_snapshot = Settings::load_sync().unwrap_or_default();
79-
Self {
79+
let mut screen = Self {
8080
visible: false,
8181
search_query: String::new(),
8282
selected_idx: 0,
8383
scroll_offset: 0,
8484
edit_field: None,
8585
edit_value: String::new(),
86-
settings_snapshot,
86+
settings_snapshot: settings_snapshot.clone(),
8787
pending_changes: HashMap::new(),
8888
auto_compact: false,
8989
notifications: true,
@@ -104,20 +104,15 @@ impl SettingsScreen {
104104
file_autocomplete_limit: "15".to_string(),
105105
file_autocomplete_show_hidden_files: false,
106106
file_injection_max_size: "100".to_string(),
107-
}
107+
};
108+
// Apply settings from snapshot immediately on initialization
109+
screen.apply_settings_from_snapshot();
110+
screen
108111
}
109112

110-
pub fn open(&mut self) {
111-
self.settings_snapshot = Settings::load_sync().unwrap_or_default();
112-
self.pending_changes.clear();
113-
self.edit_field = None;
114-
self.edit_value.clear();
115-
self.search_query.clear();
116-
self.selected_idx = 0;
117-
self.scroll_offset = 0;
118-
self.visible = true;
119-
120-
// Wire real settings from snapshot
113+
/// Apply all settings from the snapshot to the screen fields.
114+
/// This is called on initialization and when opening the settings screen.
115+
fn apply_settings_from_snapshot(&mut self) {
121116
self.auto_compact = self.settings_snapshot.auto_compact;
122117
self.notifications = self.settings_snapshot.notifications;
123118
self.show_turn_duration = self.settings_snapshot.show_turn_duration;
@@ -143,6 +138,20 @@ impl SettingsScreen {
143138
self.file_injection_max_size = self.settings_snapshot.config.file_injection_max_size.to_string();
144139
}
145140

141+
pub fn open(&mut self) {
142+
self.settings_snapshot = Settings::load_sync().unwrap_or_default();
143+
self.pending_changes.clear();
144+
self.edit_field = None;
145+
self.edit_value.clear();
146+
self.search_query.clear();
147+
self.selected_idx = 0;
148+
self.scroll_offset = 0;
149+
self.visible = true;
150+
151+
// Wire real settings from snapshot
152+
self.apply_settings_from_snapshot();
153+
}
154+
146155
pub fn close(&mut self) {
147156
self.visible = false;
148157
self.edit_field = None;
@@ -806,10 +815,12 @@ mod tests {
806815
}
807816

808817
#[test]
809-
fn all_entries_returns_sixteen_settings() {
818+
fn all_entries_returns_expected_settings() {
810819
let screen = SettingsScreen::new();
811820
let entries = all_entries(&screen);
812-
assert_eq!(entries.len(), 16, "Should have 16 editable settings");
821+
// Base settings are always present, plus 0-3 conditional file injection settings
822+
assert!(entries.len() >= 16, "Should have at least 16 editable settings, got {}", entries.len());
823+
assert!(entries.len() <= 20, "Should have at most 20 editable settings, got {}", entries.len());
813824
}
814825

815826
#[test]

0 commit comments

Comments
 (0)