Panels: unfinished corner radius and opacity values follow rollbacks too

The Corner Radius fields' edit target and the selection fields' target
(the Transparency panel's and the Control bar's Opacity fields, among
others) now include the document's rollback count. After a canceled
undo group, a new object can take the removed object's node ID; a value
typed and not yet committed for the removed object is now dropped when
the new one is selected, instead of being committed to it.

Tests cover Corner Radius for a rectangle and a polygon in the Transform
and Properties panels, and the Transparency panel's Opacity field.
This commit is contained in:
dotCooCoo committed 2026-12-05 00:29:22 -08:00
1 parent 65702eb1fe
commit 75ed49ed34
3 files changed
+78 -9

No files matched your search

+10 -9
View File
@@ -127,8 +127,8 @@ pub(crate) fn corner_length(c: &LiveCorners, k: usize) -> f64 {
}
/// What a corner field edits, as its edit target: the active document's uid, how many times
/// File › Revert and Undo or Redo replaced its content (after which a node id can name another
/// object), the selected objects in id order, and `corners`, the corners the field sets (a picked
/// File › Revert, Undo or Redo and other rollbacks (`DocState::rollbacks`) replaced its content
/// (after which a node id can name another object), the selected objects in id order, and `corners`, the corners the field sets (a picked
/// corner as its [`CornerPlace`]). A field drops a value typed and not yet committed when this
/// changes, even where the new corners have the same radius, and keeps it when the same objects
/// are selected in another order. Rounding a corner replaces its anchors without changing the
@@ -141,7 +141,7 @@ pub(crate) fn corner_target(app: &VectorcraftApp, corners: impl Hash) -> u64 {
.map(|st| {
let mut objects = st.selection.objects.to_vec();
objects.sort_unstable();
(st.uid, st.reverts, st.history_restores, objects)
(st.uid, st.reverts, st.history_restores, st.rollbacks, objects)
})
.hash(&mut hasher);
corners.hash(&mut hasher);
@@ -897,11 +897,12 @@ pub(crate) fn current_transparency(app: &VectorcraftApp) -> Option<(f32, BlendMo
Some(picked.unwrap_or((n.opacity, n.blend)))
}
/// The objects a selection field edits, as a field's edit target: the document with how many times File › Revert and
/// Undo or Redo replaced its content (after which a node id can name another object), the selected objects (or the
/// object targeted in the Layers panel) in id order, and the selected symbol part. A field with an unfinished value
/// drops it when these change, and keeps it when the same objects are selected in another order.
pub(crate) type SelectionTarget = (Option<(u64, u64, u64)>, Vec<NodeId>, Option<(NodeId, Vec<u32>)>);
/// The objects a selection field edits, as a field's edit target: the document with how many times File › Revert,
/// Undo or Redo and other rollbacks (`DocState::rollbacks`) replaced its content (after which a node id can name
/// another object), the selected objects (or the object targeted in the Layers panel) in id order, and the selected
/// symbol part. A field with an unfinished value drops it when these change, and keeps it when the same objects are
/// selected in another order.
pub(crate) type SelectionTarget = (Option<(u64, u64, u64, u64)>, Vec<NodeId>, Option<(NodeId, Vec<u32>)>);
/// The [`SelectionTarget`] of the active document.
pub(crate) fn selection_target(app: &VectorcraftApp) -> SelectionTarget {
@@ -909,7 +910,7 @@ pub(crate) fn selection_target(app: &VectorcraftApp) -> SelectionTarget {
let part = st.selection.symbol_part.as_ref().map(|p| (p.instance, p.path.clone()));
let mut subjects = st.selection.subjects().to_vec();
subjects.sort_unstable();
(Some((st.uid, st.reverts, st.history_restores)), subjects, part)
(Some((st.uid, st.reverts, st.history_restores, st.rollbacks)), subjects, part)
}
/// What the Transparency panel's and the Control bar's Opacity fields edit, as their edit target: the
@@ -145,6 +145,56 @@ fn an_unfinished_angle_does_not_reach_a_shape_that_takes_a_canceled_groups_shape
assert_eq!(p.value_role("Angle", Role::SPIN_BUTTON).as_deref(), Some("7°"), "the ellipse takes 7°, not the unfinished 3+ and 7");
}
/// A canceled undo group removes the shape a Corner Radius value was typed for, and a new shape made by `cmd` with
/// `args` takes its node ID. The value is dropped when that shape is selected in the panel `draw` draws.
fn check_corner_radius_after_a_canceled_group(draw: fn(&mut VectorcraftApp, &mut Ui), cmd: &str, args: Value, panel: &str) {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
app.run("edit.undoGroup.begin", json!({})).unwrap();
let first = app.run(cmd, args.clone()).unwrap()["id"].clone();
app.run("select.set", json!({"ids": [first]})).unwrap();
let mut p = Panel::new(app, draw);
p.click_role("Corner Radius", Role::SPIN_BUTTON);
p.key(Key::A, Modifiers::COMMAND);
p.type_text("3+");
p.app().run("edit.undoGroup.end", json!({"cancel": true})).unwrap();
let second = p.app().run(cmd, args).unwrap()["id"].clone();
assert_eq!(second, first, "{panel} {cmd}: the new shape takes the canceled group's shape's node ID");
p.app().run("select.set", json!({"ids": [second]})).unwrap();
p.frame();
let shown = p.value_role("Corner Radius", Role::SPIN_BUTTON);
assert_eq!(shown.as_deref(), Some(pt(0.0).as_str()), "{panel} {cmd}: the field shows the new shape's corner radius");
p.type_text("7");
p.key(Key::Enter, Modifiers::NONE);
p.frame();
let after = p.value_role("Corner Radius", Role::SPIN_BUTTON);
assert_eq!(after.as_deref(), Some(pt(7.0).as_str()), "{panel} {cmd}: the new shape takes 7, not the unfinished 3+ and 7");
}
#[test]
fn an_unfinished_rectangle_corner_radius_does_not_reach_a_shape_that_takes_a_canceled_groups_shapes_id() {
let rect = json!({"x": 0, "y": 0, "width": 30, "height": 30});
check_corner_radius_after_a_canceled_group(crate::panels::transform::show, "shape.rectangle", rect, "Transform");
}
#[test]
fn an_unfinished_polygon_corner_radius_does_not_reach_a_shape_that_takes_a_canceled_groups_shapes_id() {
let polygon = json!({"cx": 60, "cy": 60, "radius": 40, "sides": 5});
check_corner_radius_after_a_canceled_group(crate::panels::transform::show, "shape.polygon", polygon, "Transform");
}
#[test]
fn an_unfinished_rectangle_corner_radius_in_the_properties_panel_does_not_reach_a_shape_that_takes_a_canceled_groups_shapes_id() {
let rect = json!({"x": 0, "y": 0, "width": 30, "height": 30});
check_corner_radius_after_a_canceled_group(crate::panels::properties::show, "shape.rectangle", rect, "Properties");
}
#[test]
fn an_unfinished_polygon_corner_radius_in_the_properties_panel_does_not_reach_a_shape_that_takes_a_canceled_groups_shapes_id() {
let polygon = json!({"cx": 60, "cy": 60, "radius": 40, "sides": 5});
check_corner_radius_after_a_canceled_group(crate::panels::properties::show, "shape.polygon", polygon, "Properties");
}
/// Exit Symbol Editing Mode with nothing changed takes back the entering step, which removes the editing copy a value
/// was typed for, and a new shape can take the copy's node ID. The value is dropped when that shape is selected.
#[test]
+18
View File
@@ -744,6 +744,24 @@ mod tests {
assert_eq!(opacity_of(&panel, &b), 0.01, "Undo drops the unfinished value: 1%, not 20+1");
}
/// A canceled undo group drops an unfinished Opacity expression, though the object it takes away and the object
/// made and selected after it have the same id and opacity.
#[test]
fn unfinished_opacity_is_dropped_by_a_canceled_undo_group() {
let mut app = new_app();
run_cmd(&mut app, "edit.undoGroup.begin", json!({}));
let a = run_cmd(&mut app, "shape.rectangle", json!({"x": 0, "y": 0, "width": 30, "height": 30}))["id"].clone();
run_cmd(&mut app, "select.set", json!({"ids": [a]}));
let mut panel = Panel::new(app, show);
unfinished_opacity(&mut panel);
run_cmd(&mut panel.app(), "edit.undoGroup.end", json!({"cancel": true}));
let b = run_cmd(&mut panel.app(), "shape.rectangle", json!({"x": 50, "y": 0, "width": 30, "height": 30}))["id"].clone();
assert_eq!(b, a, "the new rectangle has the canceled group's rectangle's id");
run_cmd(&mut panel.app(), "select.set", json!({"ids": [b]}));
finish_opacity(&mut panel);
assert_eq!(opacity_of(&panel, &b), 0.01, "the canceled group drops the unfinished value: 1%, not 20+1");
}
/// The same objects selected in another order keep an unfinished Opacity expression.
#[test]
fn unfinished_opacity_stays_when_the_same_objects_are_selected_in_another_order() {