mirror of
https://github.com/storytold/filmcraft.git
synced 2026-10-14 19:26:59 -04:00
Merge pull request #1383 from vangel76/fix-1371-list-presets
#1371: export preset query also matches the format id
This commit is contained in:
commit
bd5261c8a3
2 files changed
+17
No files matched your search
@@ -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 both
|
||||
let mut s2 = demo();
|
||||
s2.export_presets.set_dir(&dir.0);
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user