diff --git a/crates/ui-egui/src/panels/properties/tests.rs b/crates/ui-egui/src/panels/properties/tests.rs index 868b83c3c7..d9301a01d0 100644 --- a/crates/ui-egui/src/panels/properties/tests.rs +++ b/crates/ui-egui/src/panels/properties/tests.rs @@ -1874,3 +1874,47 @@ fn type_quick_actions_show_text_commands_and_create_outlines() { panel.click("Retype"); assert!(crate::panel_docking::visible(&panel.app(), retype), "a second click leaves it shown"); } + +#[test] +fn canceled_property_corner_kind_keeps_the_selected_anchors_and_undo() { + use craft::ui::contract::Role; + use vectorcraft_doc::{LiveCorners, NodeId}; + use vectorcraft_geom::shapes::CornerKind; + + let mut app = new_app(); + let id = app.run("shape.star", json!({"cx": 200, "cy": 150, "radius1": 80, "radius2": 40})).unwrap()["id"].as_u64().unwrap(); + app.select_tool("directSelection"); + app.run("select.anchors", json!({"id": id, "anchors": [[0, 2]], "mode": "set"})).unwrap(); + let mut panel = Panel::new(app, show); + panel.room(egui::vec2(420.0, 920.0)); + panel.type_into("Corner Radius", "6"); + let original = panel.app().session.active().unwrap().doc.clone(); + let original_corners = LiveCorners::of(original.node(NodeId(id)).unwrap()).unwrap(); + assert_eq!(original_corners.radius(2), 6.0); + assert_eq!(original_corners.kind(2), CornerKind::Round); + let undo = undo_depth(&panel.app()); + + panel.click_role("Corner", Role::COMBO_BOX); + panel.key(Key::ArrowDown, Modifiers::NONE); + assert!(panel.app().session.active().unwrap().doc == original, "highlighting a kind leaves the star as it was"); + panel.key(Key::Escape, Modifiers::NONE); + assert!(panel.app().session.active().unwrap().doc == original); + assert_eq!(undo_depth(&panel.app()), undo); + + panel.click_role("Corner", Role::COMBO_BOX); + panel.key(Key::ArrowDown, Modifiers::NONE); + panel.key(Key::Enter, Modifiers::NONE); + { + let app = panel.app(); + let doc = &app.session.active().unwrap().doc; + let corners = LiveCorners::of(doc.node(NodeId(id)).unwrap()).unwrap(); + assert_eq!(corners.kind(2), CornerKind::ALL[1]); + for corner in [0, 1, 3, 4, 5, 6, 7, 8, 9] { + assert_eq!(corners.kind(corner), original_corners.kind(corner)); + } + assert_eq!(corners.radius(2), 6.0); + assert_eq!(undo_depth(&app), undo + 1); + } + panel.app().run("edit.undo", json!({})).unwrap(); + assert!(panel.app().session.active().unwrap().doc == original); +} diff --git a/crates/ui-egui/src/panels/properties/transform_section.rs b/crates/ui-egui/src/panels/properties/transform_section.rs index 5a9ffebe94..ad887865dc 100644 --- a/crates/ui-egui/src/panels/properties/transform_section.rs +++ b/crates/ui-egui/src/panels/properties/transform_section.rs @@ -108,7 +108,9 @@ pub(super) fn corner_rows(app: &mut VectorcraftApp, ui: &mut Ui) { // The corners differ in kind: no entry is the value. let kind = picked.kind.map_or(Mixed::Mixed, Mixed::Same); let entries = panels::corner_entries(); - let chosen = Field::new(tl!("Corner")).show(ui, |ui, _| Select::new(tl!("Corner"), Bind::given(kind), &entries).show(ui).value().copied()).inner; + let chosen = Field::new(tl!("Corner")) + .show(ui, |ui, _| Select::new(tl!("Corner"), Bind::given(kind), &entries).show(ui).events.committed().copied()) + .inner; if let Some(Some(kind)) = chosen { panels::set_picked_corners(app, &picked, json!({"kind": kind})); }