Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Guard intentional hidden selections against failures and unrelated edits

jonathnwxh67a2938cab58
diff --git a/crates/ui-egui/src/view_cmds/tests.rs b/crates/ui-egui/src/view_cmds/tests.rs
index 80ab177f0..c966f516d 100644
--- a/crates/ui-egui/src/view_cmds/tests.rs
+++ b/crates/ui-egui/src/view_cmds/tests.rs
@@ -525,3 +525,17 @@ fn creating_a_selection_restores_hidden_extras() {
}
assert!(hidden.is_empty(), "new selections stayed hidden after Extras was disabled: {hidden:?}");
}
+
+#[test]
+fn failed_selection_and_unrelated_edits_keep_extras_hidden() {
+ let (mut app, ctx) = app_with(1);
+ app.run("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap();
+ menu(&mut app, &ctx, "view.extras", json!({})).unwrap();
+ assert!(!app.ui.view.extras);
+ assert!(app.run("select.rect", json!({"x": "invalid"})).is_err());
+ assert!(!app.ui.view.extras, "failed selection must not change the view");
+ app.run("edit.fill", json!({"color": "#cc4422"})).unwrap();
+ assert!(!app.ui.view.extras, "painting an existing hidden selection keeps it hidden");
+ app.run("select.deselect", json!({})).unwrap();
+ assert!(!app.ui.view.extras, "deselecting has no new outline to reveal");
+}