mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-13 13:43:20 +00:00
This commit is contained in:
commit
eef436de45
2 files changed
+24
-1
No files matched your search
@@ -856,7 +856,9 @@ fn count_delete_group(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
s.edit("Delete Count Group", |d, _| {
|
||||
d.measurement.count_groups.remove(g);
|
||||
let n = d.measurement.count_groups.len();
|
||||
d.measurement.active_count_group = d.measurement.active_count_group.min(n.saturating_sub(1));
|
||||
// Removing a group before the active one shifts it down a slot.
|
||||
let a = d.measurement.active_count_group;
|
||||
d.measurement.active_count_group = (if g < a { a - 1 } else { a }).min(n.saturating_sub(1));
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(count_json(doc(s)?.as_ref()))
|
||||
|
||||
@@ -291,6 +291,27 @@ fn count_groups_markers_and_undo() {
|
||||
assert!(s.execute("count.add", json!({"x": 1})).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deleting_an_earlier_count_group_keeps_the_active_group() {
|
||||
let mut s = session(100, 100, 8);
|
||||
s.execute("count.add", json!({"x": 10, "y": 10})).unwrap();
|
||||
for _ in 0..3 {
|
||||
s.execute("count.newGroup", json!({})).unwrap();
|
||||
}
|
||||
s.execute("count.setGroup", json!({"group": 2})).unwrap();
|
||||
let r = s.execute("count.deleteGroup", json!({"group": 0})).unwrap();
|
||||
assert_eq!(r["activeGroup"], 1);
|
||||
assert_eq!(r["groups"][1]["name"], "Count Group 3");
|
||||
// A later group leaves the active index alone.
|
||||
let r = s.execute("count.deleteGroup", json!({"group": 2})).unwrap();
|
||||
assert_eq!(r["activeGroup"], 1);
|
||||
assert_eq!(r["groups"][1]["name"], "Count Group 3");
|
||||
// Deleting the active last group selects the new last group.
|
||||
let r = s.execute("count.deleteGroup", json!({})).unwrap();
|
||||
assert_eq!(r["activeGroup"], 0);
|
||||
assert_eq!(r["groups"][0]["name"], "Count Group 2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn log_delete_and_csv_export() {
|
||||
let mut s = session(10, 10, 8);
|
||||
|
||||
Reference in new issue
Block a user