LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LRC-LIB-KEYWORDS: keywords given to photos are stored cleaned
Nathaniel Ledford73175851e754
diff --git a/crates/engine/src/cmd/library.rs b/crates/engine/src/cmd/library.rsindex 09d19f0dd..8a4d6497b 100644--- a/crates/engine/src/cmd/library.rs+++ b/crates/engine/src/cmd/library.rs@@ -766,16 +766,26 @@ pub fn specs() -> Vec<CommandSpec> {*field = v.to_string();}}+ // keywords are stored cleaned (`a | b ` is `a|b`), each once whatever its case+ use lightcraft_catalog::keywords::{clean, same};+ let add = |m: &mut lightcraft_catalog::Meta, k: &str| {+ let k = clean(k);+ if !k.is_empty() && !m.keywords.iter().any(|x| same(x, &k)) {+ m.keywords.push(k);+ }+ };if let Some(k) = strs("keywords") {- m.keywords = k;+ m.keywords.clear();+ for k in k {+ add(&mut m, &k);+ }}for k in strs("addKeywords").unwrap_or_default() {- if !m.keywords.iter().any(|x| x.eq_ignore_ascii_case(&k)) {- m.keywords.push(k);- }+ add(&mut m, &k);}for k in strs("removeKeywords").unwrap_or_default() {- m.keywords.retain(|x| !x.eq_ignore_ascii_case(&k));+ let k = clean(&k);+ m.keywords.retain(|x| !same(&clean(x), &k));}ops.push(Op::SetMeta { id, meta: Box::new(m) });}diff --git a/crates/engine/src/tests_keyword_list.rs b/crates/engine/src/tests_keyword_list.rsindex eba8e34b0..4c0e186cf 100644--- a/crates/engine/src/tests_keyword_list.rs+++ b/crates/engine/src/tests_keyword_list.rs@@ -142,3 +142,18 @@ fn the_filter_follows_a_keyword_moved_into_a_new_parent() {assert_eq!(keywords_of(&s, id), ["Italy|Rome"]);assert_eq!(s.filter.keyword.as_deref(), Some("Italy|Rome"));}++/// Keywords given to photos are stored cleaned (" beach " is "beach", "Travel | Italy" is+/// "Travel|Italy"), so the list's actions find them; one a photo has already, whatever the case of+/// any letter, isn't added twice.+#[test]+fn keywords_given_to_photos_are_stored_cleaned() {+ let mut s = Session::with_demo();+ let id = s.visible_cloned()[0].0;+ s.execute("photo.setMeta", &json!({"ids": [id], "keywords": [" beach ", "Travel | Italy", "Ärzte"]})).unwrap();+ s.execute("photo.setMeta", &json!({"ids": [id], "addKeywords": [" sea ", "ÄRZTE", " "]})).unwrap();+ assert_eq!(keywords_of(&s, id), ["beach", "Travel|Italy", "Ärzte", "sea"]);+ s.execute("photo.setMeta", &json!({"ids": [id], "removeKeywords": ["travel | italy"]})).unwrap();+ assert_eq!(keywords_of(&s, id), ["beach", "Ärzte", "sea"]);+ assert!(s.execute("keyword.info", &json!({"keyword": "beach"})).is_ok());+}