From df357b250c0fcf4edf2681d4f114e199afb51899 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Wed, 20 May 2026 22:03:49 +0300 Subject: fix: clarify keybinding conflict warnings refs #154 --- src/config/io.rs | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'src/config/io.rs') diff --git a/src/config/io.rs b/src/config/io.rs index 12176815..3b483ba6 100644 --- a/src/config/io.rs +++ b/src/config/io.rs @@ -92,17 +92,22 @@ pub fn config_path() -> PathBuf { } pub fn config_diagnostic_summary(diagnostics: &[String]) -> Option { + const MAX_VISIBLE_DIAGNOSTICS: usize = 4; + if diagnostics.is_empty() { - None - } else if diagnostics.len() == 1 { - Some(diagnostics[0].clone()) - } else { - Some(format!( - "{} (and {} more)", - diagnostics[0], - diagnostics.len() - 1 - )) + return None; + } + + let mut lines: Vec = diagnostics + .iter() + .take(MAX_VISIBLE_DIAGNOSTICS) + .map(|diagnostic| diagnostic.split_whitespace().collect::>().join(" ")) + .collect(); + let hidden = diagnostics.len().saturating_sub(MAX_VISIBLE_DIAGNOSTICS); + if hidden > 0 { + lines.push(format!("and {hidden} more config warnings")); } + Some(lines.join("\n")) } pub fn load_live_config() -> Result> { @@ -434,6 +439,22 @@ mod tests { assert!(updated.contains("[ui.sound]\nenabled = true")); } + #[test] + fn config_diagnostic_summary_keeps_multiple_warnings_visible() { + let diagnostics = vec![ + "one".to_string(), + "two".to_string(), + "three".to_string(), + "four".to_string(), + "five".to_string(), + ]; + + assert_eq!( + config_diagnostic_summary(&diagnostics).as_deref(), + Some("one\ntwo\nthree\nfour\nand 1 more config warnings") + ); + } + #[test] fn remove_keybinding_config_sections_removes_keys_tables_only() { let content = r#"onboarding = false -- cgit v1.2.3