LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Random sort: choosing Random starts a fresh shuffle
Nathaniel Ledford6de619ca9b7f
diff --git a/crates/engine/src/cmd/library.rs b/crates/engine/src/cmd/library.rsindex 6f933252f..a2ca64eb3 100644--- a/crates/engine/src/cmd/library.rs+++ b/crates/engine/src/cmd/library.rs@@ -311,7 +311,12 @@ pub fn specs() -> Vec<CommandSpec> {Some(g) => GroupBy::parse(g).ok_or_else(|| bad("library.sort", "group must be auto|none|day|month|year"))?,None => s.sort.group,};- let seed = seed_param(p, "library.sort", s.sort.seed)?;+ let mut seed = seed_param(p, "library.sort", s.sort.seed)?;+ let explicit = p.get("seed").is_some_and(|v| !v.is_null());+ if key == SortKey::Random && s.sort.key != SortKey::Random && !explicit {+ // switching to Random is a fresh shuffle, not whatever seed was left behind+ seed = next_seed(seed, &(s.clock)());+ }s.sort = Sort { key, ascending: bool_or(p, "ascending", s.sort.ascending), group, seed };ok()}diff --git a/crates/engine/src/tests_libops.rs b/crates/engine/src/tests_libops.rsindex f9837c50e..ac0e5c57b 100644--- a/crates/engine/src/tests_libops.rs+++ b/crates/engine/src/tests_libops.rs@@ -530,3 +530,24 @@ fn random_sort_applies_to_albums_too() {let expect: Vec<_> = all.iter().filter(|i| in_album.contains(i)).copied().collect();assert_eq!(in_album, expect, "the album shows its photos in the shuffle's order, not manual order");}++/// Choosing Random from another sort is a fresh shuffle (not the fixed seed-0 order); picking it+/// again, or changing only the direction, keeps the shuffle on screen; an explicit seed wins.+#[test]+fn choosing_random_starts_a_fresh_shuffle() {+ let mut s = Session::with_demo();+ assert_eq!(s.sort.seed, 0);+ s.execute("library.sort", &json!({"key": "random"})).unwrap();+ let first = s.sort.seed;+ assert_ne!(first, 0, "the first Random is not the fixed seed-0 order");+ s.execute("library.sort", &json!({"key": "random"})).unwrap();+ s.execute("library.sort", &json!({"ascending": true})).unwrap();+ assert_eq!(s.sort.seed, first, "already random: the shuffle stays");+ s.execute("library.sort", &json!({"key": "fileName"})).unwrap();+ s.execute("library.sort", &json!({"key": "random"})).unwrap();+ assert_ne!(s.sort.seed, first, "coming back to Random reshuffles");+ s.execute("library.sort", &json!({"key": "rating"})).unwrap();+ s.execute("library.sort", &json!({"key": "random", "seed": 42})).unwrap();+ assert_eq!(s.sort.seed, 42, "an explicit seed is honoured");+ assert!(s.sort.seed < 1 << 53);+}diff --git a/docs/parity.md b/docs/parity.mdindex e1198880c..db5d72fba 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -199,7 +199,7 @@ under the UI command that wraps it (a no-op error); the UI command now wins.| LR-FILT-LOCATION | Location filter | P2 | β | `cmd:library.filter` (`text`, `ruleSet` field `location`) | free text, or a rule on location / city / state / country (smart albums, `library.filter`) || LR-FILT-PEOPLE | People filter | P2 | π‘ | `cmd:library.filter`, `crates/catalog/src/query.rs` | filter by a person's name (case-insensitive, named Face regions only) from the People view, a filter chip or `person:`; no unnamed / suggested people || LR-FILT-CULL | Culling-score filters | P2 | β | `cmd:library.filter` (`ruleSet` fields `sharpness`, `bestOfGroup`) | Focus and Best of Similar Shots in the rule editor / smart albums |-| LR-FILT-SORT | Sort | P0 | β | `cmd:library.sort`, `cmd:library.shuffle`, `crates/ui-egui/src/panels/bottombar.rs` | Random sort (seeded, stable under edits; Reshuffle picks a new seed); the shuffle is part of the saved view state; no effect in Recently Added (always newest import first); no colour-label or custom (manual) order |+| LR-FILT-SORT | Sort | P0 | β | `cmd:library.sort`, `cmd:library.shuffle`, `crates/ui-egui/src/panels/bottombar.rs` | Random sort (seeded, stable under edits; choosing Random or Reshuffle picks a new seed); the shuffle is part of the saved view state; no effect in Recently Added (always newest import first); no colour-label or custom (manual) order || LR-FILT-SAVED | Filter presets [Classic] | P2 | β | `cmd:filter.savePreset`, `cmd:filter.applyPreset`, `cmd:filter.presets`, `cmd:filter.deletePreset`, `crates/ui-egui/src/panels/filterbar.rs` | filter bar β Presets: apply, save current filter, delete (right-click); saved with the library |## E. Metadata (META)