Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge remote-tracking branch 'origin/main' into claude/fix-293-undo-shows-photo

Claude3e791905b942
diff --cc crates/engine/src/tests.rs
index 83dad8dba,0dd768877..2b09c5869
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@@ -818,28 -876,52 +876,78 @@@ fn face_job_follows_rotate_right()
assert!((pw - ph).abs() < 1e-6 * w.max(h), "square in rotated pixels: {pw} × {ph}");
}
+ /// Selecting an id that is not in the library is an error, and the selection stays as it was
+ /// (#182: `select_photos {"ids": [9999]}` answered `selected: 1` and the session lost its photo).
+ #[test]
+ fn selecting_an_unknown_photo_is_an_error_and_keeps_the_selection() {
+ let mut s = demo();
+ let vis = s.visible_cloned();
+ s.execute("library.select", &json!({"ids": [vis[0].0]})).unwrap();
+ let before = s.selection.clone();
+ for p in [
+ json!({"ids": [9999]}),
+ json!({"ids": [9999], "active": 9999}),
+ json!({"ids": [vis[1].0], "active": 9999}),
+ json!({"ids": [vis[1].0, 9999]}),
+ json!({"ids": [9999], "mode": "add"}),
+ json!({"ids": [9999], "mode": "toggle"}),
+ json!({"ids": [9999], "mode": "range"}),
+ ] {
+ let e = s.execute("library.select", &p).unwrap_err().to_string();
+ assert!(e.contains("no such photo 9999"), "{p}: {e}");
+ assert_eq!(s.selection, before, "{p}");
+ }
+ assert_eq!(s.active(), Some(vis[0]));
+ assert!(s.execute("develop.get", &json!({})).is_ok());
+ // queries about an explicit id check it too
+ for c in ["develop.get", "photo.inspect", "photo.allMetadata", "history.list"] {
+ let e = s.execute(c, &json!({"id": 9999})).unwrap_err().to_string();
+ assert!(e.contains("no such photo 9999"), "{c}: {e}");
+ assert!(s.execute(c, &json!({"id": vis[1].0})).is_ok(), "{c}");
+ }
+ // an empty selection is still allowed
+ assert_eq!(s.execute("library.select", &json!({"ids": []})).unwrap()["selected"], 0);
+ }
+
+ /// A preset saved by another version may hold keys this one doesn't know: exporting with it keeps
+ /// working (the stale keys are dropped), while a typo the caller makes is still refused (#181).
+ #[test]
+ fn saved_presets_with_unknown_keys_still_export() {
+ use crate::export::{ExportOptions, ExportPreset};
+ let mut s = demo();
+ s.export_presets.push(ExportPreset {
+ name: "Old".into(),
+ params: json!({"format": "png", "retiredOption": 3, "watermark": {"text": "©", "retiredKey": true}}),
+ });
+ let p = s.export_params(&json!({"preset": "old", "quality": 80})).unwrap();
+ let o = ExportOptions::from_params(&p).unwrap();
+ assert_eq!(o.format, crate::export::ExportFormat::Png);
+ assert_eq!(o.watermark.map(|w| w.text), Some("©".to_string()));
+ assert!(ExportOptions::from_params(&s.export_params(&json!({"preset": "old", "qualty": 80})).unwrap()).is_err());
+ }
++
+/// Undo and redo bring the photo they change on screen (issue #293): after editing one photo and
+/// moving on, Undo makes it the active photo again; a step that changes several photos leaves the
+/// selection alone.
+#[test]
+fn undo_and_redo_show_the_photo_they_change() {
+ let mut s = demo();
+ let vis = s.visible_cloned();
+ let (a, b) = (vis[0], vis[1]);
+ s.execute("library.select", &json!({"ids": [a.0]})).unwrap();
+ s.execute("develop.set", &json!({"control": "light.exposure", "value": 1.0})).unwrap();
+ s.execute("library.select", &json!({"ids": [b.0]})).unwrap();
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert_eq!(s.active(), Some(a), "undo shows the photo it changed");
+ assert_eq!(s.selection.ids, vec![a]);
+ s.execute("library.select", &json!({"ids": [b.0]})).unwrap();
+ s.execute("edit.redo", &json!({})).unwrap();
+ assert_eq!(s.active(), Some(a), "so does redo");
+ // rating both selected photos is one step over two photos: undoing it leaves the selection
+ s.execute("library.select", &json!({"ids": [a.0, b.0], "active": b.0})).unwrap();
+ s.execute("photo.rate", &json!({"rating": 3})).unwrap();
+ s.execute("library.select", &json!({"ids": [a.0, b.0], "active": a.0})).unwrap();
+ let before = s.selection.clone();
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert_eq!(s.selection, before, "a step over several photos keeps the selection");
+}