LR-FILT-LABEL: group the plural labels in the chip when label and labels exclude each other

This commit is contained in:
Marco Arnulfo
2026-10-24 14:51:44 +02:00
parent afbd931561
commit ab28690d06
4 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -332,7 +332,7 @@ fn filter_label_and_labels_together_chip() {
// nothing passes both: the chip names both constraints
s.execute("library.filter", &json!({"label": "red", "labels": ["yellow", "green"]})).unwrap();
assert_eq!(s.visible_cloned().len(), 0);
assert_eq!(chip(&s).label, "Label: Red and Yellow or Green");
assert_eq!(chip(&s).label, "Label: Red and (Yellow or Green)");
s.execute("library.filter", &chip(&s).clear).unwrap();
assert_eq!((s.filter.label, s.filter.labels.len()), (None, 0));
}
+7 -2
View File
@@ -164,8 +164,13 @@ pub fn filter_chips(f: &Filter, cat: &Catalog) -> Vec<FilterChip> {
if let Some(shown) = f.labels_shown() {
let or = |ls: &[lightcraft_catalog::ColorLabel]| ls.iter().map(|l| cat.label_name(*l)).collect::<Vec<_>>().join(" or ");
// empty: `label` and `labels` exclude each other, so name both constraints
let names =
if shown.is_empty() { format!("{} and {}", f.label.map(|l| cat.label_name(l)).unwrap_or_default(), or(&f.labels)) } else { or(&shown) };
let names = if shown.is_empty() {
// parenthesised when plural, so "Red and Yellow or Green" cannot read as "(Red and Yellow) or Green"
let plural = if f.labels.len() > 1 { format!("({})", or(&f.labels)) } else { or(&f.labels) };
format!("{} and {plural}", f.label.map(|l| cat.label_name(l)).unwrap_or_default())
} else {
or(&shown)
};
add(format!("Label: {names}"), json!({"label": Null, "labels": []}));
}
if let Some(k) = f.kind {