FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
#1371: export preset query also matches the format id
vangel765553e26e120c
diff --git a/crates/engine/src/export_tests.rs b/crates/engine/src/export_tests.rsindex d5f1883ec..b4690748c 100644--- a/crates/engine/src/export_tests.rs+++ b/crates/engine/src/export_tests.rs@@ -360,6 +360,13 @@ fn user_presets_persist_with_favourites_import_and_export() {assert_eq!(favs, 2);let hits = s.execute("export.presets.list", json!({"query": "prores"})).unwrap()["presets"].as_array().unwrap().len();assert_eq!(hits, 8, "seven QuickTime ProRes presets and MXF OP1a ProRes 422 HQ");+ // #1371: the query also matches the format id and the normalised label+ let h264_only = s.execute("export.presets.list", json!({"format": "h264"})).unwrap()["presets"].as_array().unwrap().len();+ let mut count = |q: &str| s.execute("export.presets.list", json!({"query": q})).unwrap()["presets"].as_array().unwrap().len();+ assert!(count("h264") > 0, "format id `h264` finds the H.264 presets");+ assert!(count("h264") >= h264_only, "every h264 preset is found by its format id");+ assert_eq!(count("h.264"), count("H.264"));+ assert!(count("h.264") >= h264_only);// persisted: a fresh session with the same data directory sees bothlet mut s2 = demo();s2.export_presets.set_dir(&dir.0);diff --git a/crates/engine/src/export_tools.rs b/crates/engine/src/export_tools.rsindex 1d316aa5b..6f4c8b26e 100644--- a/crates/engine/src/export_tools.rs+++ b/crates/engine/src/export_tools.rs@@ -953,8 +953,14 @@ fn preset_json(s: &Session, pr: &ExportPreset, full: bool) -> Value {v}+/// Lower-cased alphanumerics only, so `h264`, `h.264` and `H.264` compare equal.+fn squash_alnum(s: &str) -> String {+ s.chars().filter(|c| c.is_alphanumeric()).flat_map(char::to_lowercase).collect()+}+fn presets_list(s: &mut Session, p: &Value) -> Result<Value> {let query = str_p(p, "query").unwrap_or("").to_ascii_lowercase();+ let squashed = squash_alnum(&query);let cat = str_p(p, "category").map(str::to_ascii_lowercase);let fav = bool_p(p, "favorites").unwrap_or(false);let fmt = str_p(p, "format").and_then(Format::from_name);@@ -967,6 +973,10 @@ fn presets_list(s: &mut Session, p: &Value) -> Result<Value> {|| x.name.to_ascii_lowercase().contains(&query)|| x.description.to_ascii_lowercase().contains(&query)|| x.category.to_ascii_lowercase().contains(&query)+ // The format id (`h264`) and label (`H.264`) are equivalent spellings.+ || (!squashed.is_empty()+ && (squash_alnum(x.settings.format.id()).contains(&squashed)+ || squash_alnum(x.settings.format.label()).contains(&squashed)))}).filter(|x| cat.as_ref().is_none_or(|c| x.category.to_ascii_lowercase() == *c)).filter(|x| !fav || s.export_presets.is_favorite(&x.name))