LR-FILT-FLAG: group the plural flags in the chip when flag and flags exclude each other

This commit is contained in:
Marco Arnulfo
2026-10-30 02:26:41 +01:00
parent e7fa046d11
commit cdc1505bb3
4 changed files with 12 additions and 3 deletions
+1 -1
View File
@@ -409,7 +409,7 @@ fn filter_flag_and_flags_together_chip() {
// nothing passes both: the chip names both constraints
s.execute("library.filter", &json!({"flag": "pick", "flags": ["reject", "none"]})).unwrap();
assert_eq!(s.visible_cloned().len(), 0);
assert_eq!(chip(&s), "Flag: pick and reject or none");
assert_eq!(chip(&s), "Flag: pick and (reject or none)");
}
/// Quick Collection / target album: B toggles the selection in it (created on first use);
+7 -1
View File
@@ -162,7 +162,13 @@ pub fn filter_chips(f: &Filter, cat: &Catalog) -> Vec<FilterChip> {
let name = |fl: &lightcraft_catalog::Flag| format!("{fl:?}").to_lowercase();
let or = |fls: &[lightcraft_catalog::Flag]| fls.iter().map(name).collect::<Vec<_>>().join(" or ");
// empty: `flag` and `flags` exclude each other, so name both constraints
let names = if shown.is_empty() { format!("{} and {}", f.flag.as_ref().map(name).unwrap_or_default(), or(&f.flags)) } else { or(&shown) };
let names = if shown.is_empty() {
// parenthesised when plural, so "pick and reject or none" cannot read as "(pick and reject) or none"
let plural = if f.flags.len() > 1 { format!("({})", or(&f.flags)) } else { or(&f.flags) };
format!("{} and {plural}", f.flag.as_ref().map(name).unwrap_or_default())
} else {
or(&shown)
};
add(format!("Flag: {names}"), json!({"flag": Null, "flags": []}));
}
if let Some(shown) = f.labels_shown() {
+2
View File
@@ -607,6 +607,8 @@ fn german_switches_via_menu_and_control_and_persists() {
assert_eq!(filter_label(&filter, &app.session.catalog), "Markierung: ausgewählt oder keine");
let filter = lightcraft_catalog::Filter { flag: Some(lightcraft_catalog::Flag::Pick), ..filter };
assert_eq!(filter_label(&filter, &app.session.catalog), "Markierung: ausgewählt");
let filter = lightcraft_catalog::Filter { flags: vec![lightcraft_catalog::Flag::Reject, lightcraft_catalog::Flag::None], ..filter };
assert_eq!(filter_label(&filter, &app.session.catalog), "Markierung: ausgewählt und (abgelehnt oder keine)");
set_language(Locale::En);
}
+2 -1
View File
@@ -73,7 +73,8 @@ pub(crate) fn display_label(chip: &FilterChip, filter: &lightcraft_catalog::Filt
let name = |flag: &lightcraft_catalog::Flag| tr(&format!("{flag:?}").to_lowercase()).to_string();
let or = |flags: &[lightcraft_catalog::Flag]| flags.iter().map(name).collect::<Vec<_>>().join(&format!(" {} ", tr("or")));
let names = if shown.is_empty() {
format!("{} {} {}", filter.flag.as_ref().map(name).unwrap_or_default(), tr("and"), or(&filter.flags))
let plural = if filter.flags.len() > 1 { format!("({})", or(&filter.flags)) } else { or(&filter.flags) };
format!("{} {} {plural}", filter.flag.as_ref().map(name).unwrap_or_default(), tr("and"))
} else {
or(&shown)
};