diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-22 23:36:43 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-22 23:36:43 +0300 |
| commit | 088922dfabca152047c8f39f660893b3b19dbe2d (patch) | |
| tree | 81e4b960e0417f4fc0fcb368fb093511f26670e7 /src/app | |
| parent | d7ae163f8888cd9bf13e5a34e4d37f9518f76c01 (diff) | |
fix: let user keybinds displace defaults
refs #747
Diffstat (limited to 'src/app')
| -rw-r--r-- | src/app/mod.rs | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/app/mod.rs b/src/app/mod.rs index 4fd94697..bf4fecca 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1272,11 +1272,12 @@ impl App { |section: &str| invalid_sections.iter().any(|invalid| invalid == section); if !invalid_section("keys") { - match config.live_keybinds() { - Ok(live) => { + match config.live_keybinds_with_diagnostics() { + Ok((live, keybind_diagnostics)) => { self.state.prefix_code = live.prefix.0; self.state.prefix_mods = live.prefix.1; self.state.keybinds = live.keybinds; + diagnostics.extend(keybind_diagnostics); } Err(keybind_diagnostics) => { diagnostics.extend( @@ -2617,7 +2618,7 @@ mod tests { } #[test] - fn reload_config_keeps_current_keybinds_on_invalid_binding_but_applies_other_sections() { + fn reload_config_disables_invalid_binding_but_applies_valid_keymap_and_other_sections() { let _guard = config_env_lock().lock().unwrap(); let path = temp_config_path("reload-config-invalid-keybind"); std::fs::create_dir_all(path.parent().unwrap()).unwrap(); @@ -2630,7 +2631,6 @@ mod tests { let mut app = test_app(); let original_prefix = (app.state.prefix_code, app.state.prefix_mods); - let original_keybinds = app.state.keybinds.new_workspace.clone(); let report = app.reload_config(); assert_eq!(report.status, crate::config::ConfigReloadStatus::Partial); @@ -2638,7 +2638,7 @@ mod tests { (app.state.prefix_code, app.state.prefix_mods), original_prefix ); - assert_eq!(app.state.keybinds.new_workspace, original_keybinds); + assert!(app.state.keybinds.new_workspace.bindings.is_empty()); assert_eq!( app.state.toast_config.delivery, crate::config::ToastDelivery::Terminal @@ -2648,7 +2648,7 @@ mod tests { .config_diagnostic .as_deref() .is_some_and(|message| { - message.contains("keys.new_workspace") && message.contains("kept current keybinds") + message.contains("keys.new_workspace") && message.contains("disabling binding") })); std::env::remove_var(crate::config::CONFIG_PATH_ENV_VAR); @@ -2656,6 +2656,36 @@ mod tests { } #[test] + fn reload_config_user_binding_displaces_default_without_rejecting_prefix() { + let _guard = config_env_lock().lock().unwrap(); + let path = temp_config_path("reload-config-user-binding-displaces-default"); + std::fs::create_dir_all(path.parent().unwrap()).unwrap(); + std::fs::write( + &path, + "[keys]\nprefix = \"ctrl+space\"\nprevious_workspace = \"prefix+shift+l\"\n", + ) + .unwrap(); + std::env::set_var(crate::config::CONFIG_PATH_ENV_VAR, &path); + + let mut app = test_app(); + let report = app.reload_config(); + + assert_eq!(report.status, crate::config::ConfigReloadStatus::Applied); + assert_eq!(app.state.prefix_code, KeyCode::Char(' ')); + assert_eq!(app.state.prefix_mods, KeyModifiers::CONTROL); + assert!(app + .state + .keybinds + .previous_workspace + .matches_prefix(&KeyEvent::new(KeyCode::Char('l'), KeyModifiers::SHIFT))); + assert!(app.state.keybinds.swap_pane_right.bindings.is_empty()); + assert!(app.state.config_diagnostic.is_none()); + + std::env::remove_var(crate::config::CONFIG_PATH_ENV_VAR); + let _ = std::fs::remove_dir_all(path.parent().unwrap()); + } + + #[test] fn reload_config_preserves_invalid_ui_section_but_applies_valid_keys() { let _guard = config_env_lock().lock().unwrap(); let path = temp_config_path("reload-config-invalid-ui-section"); |
