diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 0697409c21..cb87960ff6 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1119,8 +1119,19 @@ impl PhotocraftApp { // Making a new selection reveals its outline after View > Extras was hidden (#5597). // These interactive selection commands complete inline; a failed command, deselection, // or painting inside an existing selection must leave the user's view choice alone. - if r.is_ok() - && matches!(id, "select.rect" | "select.lasso" | "select.magicWand" | "select.loadSelection" | "select.loadLuminosity") + if r.as_ref().is_ok_and(|v| v.get("changed") != Some(&Value::Bool(false)) && v.get("pending") != Some(&Value::Bool(true))) + && matches!( + id, + "select.rect" + | "select.lasso" + | "select.magneticLasso" + | "select.magicWand" + | "select.quick" + | "select.object" + | "select.loadSelection" + | "select.loadLuminosity" + | "path.toSelection" + ) && self.session.active().is_some_and(|st| st.doc.selection.is_some()) { self.ui.view.extras = true; diff --git a/crates/ui-egui/src/path_selection_tests.rs b/crates/ui-egui/src/path_selection_tests.rs index a1cec58060..12b1670863 100644 --- a/crates/ui-egui/src/path_selection_tests.rs +++ b/crates/ui-egui/src/path_selection_tests.rs @@ -352,3 +352,16 @@ fn thumbnail_selection_after_hiding_extras_restores_outline() { assert!(h.state().ui.view.shows(h.state().ui.view.show.selection_edges), "Ctrl-clicking the thumbnail reveals the new selection"); assert_eq!(h.state().session.active().unwrap().active_layer, Some(photocraft_doc::LayerId(active))); } + +#[test] +fn loading_a_path_after_hiding_extras_restores_outline() { + let mut h = harness(); + h.state_mut().run("path.set", json!({"name": "work", "path": rect_path(10.0, 10.0, 50.0, 40.0)})).unwrap(); + h.state_mut().ui.tool = Tool::Pen; + let ctx = h.ctx.clone(); + crate::menus::invoke(h.state_mut(), &ctx, "view.extras", json!({})).unwrap(); + assert!(!h.state().ui.view.extras); + press(&mut h, Key::Enter, command()); + assert_eq!(selection(&h), Some([10, 10, 50, 40])); + assert!(h.state().ui.view.shows(h.state().ui.view.show.selection_edges)); +} diff --git a/crates/ui-egui/src/view_cmds/tests.rs b/crates/ui-egui/src/view_cmds/tests.rs index 299a47d22f..83611d0e1a 100644 --- a/crates/ui-egui/src/view_cmds/tests.rs +++ b/crates/ui-egui/src/view_cmds/tests.rs @@ -514,7 +514,9 @@ fn creating_a_selection_restores_hidden_extras() { ("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})), ("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20, "ellipse": true})), ("select.lasso", json!({"points": [[10,10], [30,10], [20,30]]})), + ("select.magneticLasso", json!({"points": [[10,10], [30,10], [20,30]], "trace": false})), ("select.magicWand", json!({"x": 10, "y": 10})), + ("select.quick", json!({"points": [[10,10]], "size": 8})), ("select.loadSelection", json!({"channel": "transparency"})), ("select.loadLuminosity", json!({})), ] { @@ -556,3 +558,15 @@ fn new_selection_preserves_individual_show_preferences() { assert!(!app.ui.view.show.selection_edges); assert!(!app.ui.view.show.grid); } + +#[test] +fn object_selection_finding_nothing_keeps_extras_hidden() { + let (mut app, ctx) = app_with(1); + app.run("edit.fill", json!({"color": "#ffffff"})).unwrap(); + app.run("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); + menu(&mut app, &ctx, "view.extras", json!({})).unwrap(); + let result = app.run("select.object", json!({"point": [3,3]})).unwrap(); + assert_eq!(result["changed"], false); + assert!(app.session.active().unwrap().doc.selection.is_some()); + assert!(!app.ui.view.extras, "finding no object must not reveal an old selection"); +}