From 16f8f7e8a0b89e7f00dc94ce2274845fd70078f9 Mon Sep 17 00:00:00 2001 From: Zinadin Zidan Date: Fri, 6 Nov 2026 01:34:21 +0600 Subject: [PATCH] Grid: one selected photo shows "1 selected" in the header (#3776) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Library grid's header added the selection count only from two selected photos up, so selecting one showed nothing, while the reference app shows "1 selected". It now shows from one. The Spanish, Brazilian Portuguese and Swedish strings were plural-only ("1 seleccionadas"); they now read "Seleccionadas: 1 · ...", the noun-first form Italian and Polish already use. --- crates/ui-egui/locales/es-formats.json | 2 +- crates/ui-egui/locales/pt-br-formats.json | 2 +- crates/ui-egui/locales/sv-formats.json | 2 +- crates/ui-egui/src/panels/grid.rs | 2 +- .../ui-egui/src/panels/grid/header_tests.rs | 35 +++++++++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/locales/es-formats.json b/crates/ui-egui/locales/es-formats.json index 7b697e946b..32547eebe8 100644 --- a/crates/ui-egui/locales/es-formats.json +++ b/crates/ui-egui/locales/es-formats.json @@ -169,7 +169,7 @@ "{n} photo{} now · updates automatically as photos change": "{n} foto{} ahora · se actualiza automáticamente cuando cambian las fotos", "{n} selected photo{} · {pages} page{}": "{n} foto{0} seleccionada{0} · {pages} página{1}", "{pid} (missing)": "{pid} (falta)", - "{sel_n} selected · {counted}": "{sel_n} seleccionadas · {counted}", + "{sel_n} selected · {counted}": "Seleccionadas: {sel_n} · {counted}", "{stage}… {:.0}%": "{stage}… {:.0}%", "{verb} {n} Photo{}": "{verb} {n} foto{}", "{weekday}, {day}": "{weekday}, {day}", diff --git a/crates/ui-egui/locales/pt-br-formats.json b/crates/ui-egui/locales/pt-br-formats.json index 83d5a37518..e547bee56a 100644 --- a/crates/ui-egui/locales/pt-br-formats.json +++ b/crates/ui-egui/locales/pt-br-formats.json @@ -128,7 +128,7 @@ "{n} photo{} match · updates automatically as photos change": "{n} foto{0} correspondente{0} · atualiza automaticamente conforme as fotos mudam", "{n} photo{} now · updates automatically as photos change": "{n} foto{} agora · atualiza automaticamente conforme as fotos mudam", "{n} selected photo{} · {pages} page{}": "{n} foto{0} selecionada{0} · {pages} página{1}", - "{sel_n} selected · {counted}": "{sel_n} selecionadas · {counted}", + "{sel_n} selected · {counted}": "Selecionadas: {sel_n} · {counted}", "{stage}… {:.0}%": "{stage}… {:.0}%", "{verb} {n} Photo{}": "{verb} {n} foto{}", "{weekday}, {day}": "{weekday}, {day}", diff --git a/crates/ui-egui/locales/sv-formats.json b/crates/ui-egui/locales/sv-formats.json index 7d40388d1b..68995acf5c 100644 --- a/crates/ui-egui/locales/sv-formats.json +++ b/crates/ui-egui/locales/sv-formats.json @@ -253,7 +253,7 @@ "{pct} %": "{pct} %", "{photos} catalog records processed; {collections} collections.": "{photos} katalogposter bearbetade; {collections} samlingar.", "{pid} (missing)": "{pid} (saknas)", - "{sel_n} selected · {counted}": "{sel_n} markerade · {counted}", + "{sel_n} selected · {counted}": "Markerade: {sel_n} · {counted}", "{size} GB": "{size} GB", "{stage}… {:.0}%": "{stage}… {:.0} %", "{s} s of AV1 video": "{s} s AV1-video", diff --git a/crates/ui-egui/src/panels/grid.rs b/crates/ui-egui/src/panels/grid.rs index db4dfa1b83..2c16c38047 100644 --- a/crates/ui-egui/src/panels/grid.rs +++ b/crates/ui-egui/src/panels/grid.rs @@ -298,7 +298,7 @@ fn show_inner(app: &mut LightcraftApp, ui: &mut egui::Ui) { let chips = lightcraft_engine::filter_chips(&app.session.filter, &app.session.catalog); let total = app.session.source_total(); let counted = super::chips::count_text(ids.len(), total, !chips.is_empty()); - let cnt = if sel_n > 1 { crate::i18n::tr_format!("{sel_n} selected · {counted}", counted = counted, sel_n = sel_n) } else { counted }; + let cnt = if sel_n > 0 { crate::i18n::tr_format!("{sel_n} selected · {counted}", counted = counted, sel_n = sel_n) } else { counted }; match app.session.browse.clone().filter(|_| app.session.source == lightcraft_engine::LibrarySource::Folder) { Some(b) => { let local = app.caches.grid.local(&app.session.catalog, &ids, generation); diff --git a/crates/ui-egui/src/panels/grid/header_tests.rs b/crates/ui-egui/src/panels/grid/header_tests.rs index 463991625e..88b992d3b4 100644 --- a/crates/ui-egui/src/panels/grid/header_tests.rs +++ b/crates/ui-egui/src/panels/grid/header_tests.rs @@ -17,6 +17,41 @@ fn breadcrumbs_open_their_folder_as_spelled() { assert!(to("").is_empty() && to("/").is_empty() && to(r"\\").is_empty()); } +/// Issue #3776: one selected photo is counted in the header as two or more are ("1 selected · 3 +/// photos"); with nothing selected the header shows the photo count alone. +#[test] +fn the_header_counts_a_single_selected_photo() { + use lightcraft_catalog::{Op, Photo, Source}; + for selected in [0, 1, 2] { + let mut session = lightcraft_engine::Session::new(); + for i in 0..3 { + let id = session.catalog.alloc_photo_id(); + let p = Photo::new(id, Source::File { path: format!("/pics/{i}.jpg") }, "x.jpg", "JPEG", 60, 40, "2026-01-01T10:00:00"); + session.catalog.apply(Op::AddPhoto { photo: Box::new(p) }).unwrap(); + } + session.selection.ids = session.catalog.photos().take(selected).map(|p| p.id).collect(); + let mut app = LightcraftApp::new(session, Services { png: None, ..Default::default() }); + app.ui.view = crate::state::ViewMode::PhotoGrid; + let mut h = crate::headless::Headless::new(app, [1400.0, 900.0], 1.0); + h.step(); + h.step(); + assert_eq!(h.app.session.selection.ids.len(), selected, "the selection is kept"); + let painted = h.painted_text(); + let expected = if selected == 0 { "3 photos".to_string() } else { format!("{selected} selected · 3 photos") }; + assert!(painted.contains(&expected), "{selected} selected: the header shows {expected:?}: {painted:?}"); + if selected == 0 { + assert!(!painted.iter().any(|s| s.contains("selected ·")), "nothing selected, no count: {painted:?}"); + } + } + // a language whose word for "selected" agrees with the number reads "noun: number", right for one as for many + for (locale, expected) in [(Locale::Es, "Seleccionadas: 1 · x"), (Locale::PtBr, "Selecionadas: 1 · x"), (Locale::Sv, "Markerade: 1 · x")] { + crate::i18n::set_language(locale); + let one = crate::i18n::tr_format!("{sel_n} selected · {counted}", sel_n = 1, counted = "x"); + crate::i18n::set_language(Locale::En); + assert_eq!(one, expected, "{locale:?}"); + } +} + fn text_bounds(shape: &egui::Shape, out: &mut Vec) { match shape { egui::Shape::Text(text) => out.push(text.visual_bounding_rect()),