LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LRC-LIB-KEYWORDS: typed new keywords go inside the default parent
Nathaniel Ledford334868b73a56
diff --git a/crates/catalog/src/keywords.rs b/crates/catalog/src/keywords.rsindex b79d245ac..d01c06741 100644--- a/crates/catalog/src/keywords.rs+++ b/crates/catalog/src/keywords.rs@@ -345,6 +345,17 @@ impl Catalog {self.keyword_path(path).is_some()}+ /// Where a keyword typed for a photo goes: inside the default parent when it is a new name (Put+ /// New Keywords Inside This Keyword); a keyword the library has, or a path typed whole, as+ /// typed (cleaned).+ pub fn typed_keyword(&self, typed: &str) -> String {+ let k = clean(typed);+ match self.default_keyword_parent() {+ Some(parent) if !k.is_empty() && !k.contains(SEP) && !self.has_keyword(&k) => format!("{parent}{SEP}{k}"),+ _ => k,+ }+ }+/// `path` with each level the library has spelled as the library spells it (`TRAVEL|Rome` next/// to `travel|italy` is `travel|Rome`).fn spelled(&self, path: &str) -> String {@@ -1012,6 +1023,19 @@ mod tests {assert!(!c.keyword_suggestions(&["events|weddings".into()], "wed", 5).contains(&"Events|Weddings".to_string()), "not one it has");}+ /// A new name typed for a photo goes inside the default parent; a keyword the library has, and+ /// a path typed whole, don't.+ #[test]+ fn typed_new_keywords_go_inside_the_default_parent() {+ let (mut c, _) = lib(&[&["beach"], &["Events"]]);+ assert_eq!(c.typed_keyword(" Weddings "), "Weddings", "no default parent");+ let op = c.set_default_parent_ops(Some("events")).unwrap();+ c.apply(op).unwrap();+ assert_eq!(c.typed_keyword("Weddings"), "Events|Weddings");+ assert_eq!(c.typed_keyword("BEACH"), "BEACH", "the library has it");+ assert_eq!(c.typed_keyword("Places|Lisbon"), "Places|Lisbon");+ }+#[test]fn suggestions_rank_co_occurrence_and_prefixes() {let (c, _) = lib(&[&["dog", "park"], &["dog", "park", "ball"], &["dog", "beach"], &["cat"], &["cat"], &["cat"], &["parade"], &["eagle"]]);diff --git a/crates/ui-egui/src/panels/right.rs b/crates/ui-egui/src/panels/right.rsindex f8a817955..23915c84a 100644--- a/crates/ui-egui/src/panels/right.rs+++ b/crates/ui-egui/src/panels/right.rs@@ -776,7 +776,8 @@ fn keywords(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId) {let r = ui.add(egui::TextEdit::singleline(&mut text).hint_text(crate::i18n::tr("Add keyword")).desired_width(f32::INFINITY));register(ui.ctx(), "field:keyword", r.rect);if r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) && !text.trim().is_empty() {- let kws: Vec<String> = text.split(',').map(|s| s.trim().to_string()).filter(|s| !s.is_empty()).collect();+ // a new name goes inside the default parent (Put New Keywords Inside This Keyword)+ let kws: Vec<String> = text.split(',').map(|s| app.session.catalog.typed_keyword(s)).filter(|s| !s.is_empty()).collect();let _ = app.run("photo.setMeta", json!({"addKeywords": kws}));text.clear();}diff --git a/crates/ui-egui/src/tests_keyword_list.rs b/crates/ui-egui/src/tests_keyword_list.rsindex 6c638562a..f736efcb8 100644--- a/crates/ui-egui/src/tests_keyword_list.rs+++ b/crates/ui-egui/src/tests_keyword_list.rs@@ -400,3 +400,20 @@ fn a_tick_box_doesnt_start_a_drag() {assert_eq!(h.app.ui.dragging_keyword, None);release(&mut h, from + egui::vec2(0.0, 60.0));}++/// Keywords typed in the Keywords panel's box go inside the default parent too when they are+/// new (Lightroom Classic's Put New Keywords Inside This Keyword); keywords the library has, and+/// paths typed whole, stay as typed.+#[test]+fn typed_keywords_go_inside_the_default_parent() {+ let (mut h, ids) = keywords_panel();+ run(&mut h, "keyword.create", json!({"name": "Events"}));+ run(&mut h, "keyword.setDefaultParent", json!({"keyword": "Events"}));+ ask(&mut h, "ui.clickWidget", json!({"id": "field:keyword"}));+ ask(&mut h, "ui.text", json!({"text": "Birthdays, mountains, Places|Lisbon"}));+ ask(&mut h, "ui.key", json!({"key": "Enter"}));+ let k = keywords_of(&h, ids[0]);+ for want in ["Events|Birthdays", "mountains", "Places|Lisbon"] {+ assert!(k.contains(&want.to_string()), "{want}: {k:?}");+ }+}