Shapes: a batch step that switches tools keeps the batch's earlier steps

A batch run during a widget drag settles the drag first. A tool or
document switch inside the batch then ended the drag with a Cancel,
which undid the batch's open interaction and its earlier steps in that
document. Deactivating a tool in a batch now leaves the Cancel out, for
the blend, corner, pie and side widgets alike.
This commit is contained in:
dotCooCoo
2026-11-18 02:00:11 -08:00
parent 255cdcb6ca
commit fac3cb8013
3 changed files with 49 additions and 7 deletions
+1 -2
View File
@@ -204,8 +204,7 @@ impl Session {
let _ = self.finish_tool_edit_later();
// The switch goes on whatever the lent tool's last actions did, as for the deactivation.
let _ = self.give_back_tool(view);
let acts = self.with_tool_cx(view, |t, cx| t.deactivate(cx));
let _ = self.apply_actions(acts);
let _ = self.deactivate_tool(view);
// A batch leaves its interaction open in the document it leaves, to keep or roll back with
// the rest of the batch; anything else in progress (a drag) is cancelled.
if self.batch_stash.is_none() {
+15 -5
View File
@@ -188,8 +188,7 @@ impl Session {
.then(|| self.tool.options().get("meshPoints").cloned())
.flatten()
.filter(|v| v.as_array().is_some_and(|a| !a.is_empty()));
let acts = self.with_tool_cx(view, |t, cx| t.deactivate(cx));
self.apply_actions(acts)?;
self.deactivate_tool(view)?;
self.keep_tool_settings();
self.tool = self.make_tool(id);
if let Some(selection) = text_selection {
@@ -205,6 +204,18 @@ impl Session {
Ok(())
}
/// Deactivate the tool and apply the actions it returns. In a batch, a Cancel is left out: the
/// batch settled the tool's drag when it began, and the open interaction holds the batch's
/// steps, which the batch keeps or rolls back as a whole.
pub(crate) fn deactivate_tool(&mut self, view: ViewInfo) -> Result<()> {
let mut acts = self.with_tool_cx(view, |t, cx| t.deactivate(cx));
if self.batch_stash.is_some() {
acts.retain(|a| !matches!(a, Action::Cancel));
}
self.apply_actions(acts)?;
Ok(())
}
/// The selection tools other than Direct Selection pick whole objects: with one of them chosen,
/// an object selected in a symbol instance's art gives way to the instance. The revision
/// changes with it, so panels that cache by revision show the instance.
@@ -297,8 +308,7 @@ impl Session {
// them all (#8090). Group Selection picks no mesh points, so the Eyedropper keeps its own.
let mesh_points =
(lender.id() == "eyedropper" && self.tool.id() != "groupSelection").then(|| self.tool.options().get("meshPoints").cloned()).flatten();
let acts = self.with_tool_cx(view, |t, cx| t.deactivate(cx));
let r = self.apply_actions(acts);
let r = self.deactivate_tool(view);
self.keep_tool_settings();
self.tool = lender;
if let Some(points) = mesh_points {
@@ -311,7 +321,7 @@ impl Session {
self.lent_selection = left;
}
self.after_command(None);
r.map(drop)
r
}
/// A fresh `id` tool with the options it keeps ([`settings`]): its last values, from this
+33
View File
@@ -67,3 +67,36 @@ fn a_side_widget_drag_changes_a_polygons_sides_in_one_undo_step() {
assert_eq!(polygon(&mut h), before);
assert_eq!(h.session.doc().unwrap().history.undo.len(), steps);
}
/// A batch run during a side widget drag settles the drag first. A batch step that switches
/// documents then ends the drag without undoing the batch's own steps in the document it leaves.
#[test]
fn a_batch_that_switches_documents_during_a_side_widget_drag_keeps_its_steps() {
let mut h = Headless::new();
for _ in 0..2 {
h.call("engine.execute", json!({"command": "file.new", "params": {"width": 300, "height": 300}})).unwrap();
}
h.call("engine.execute", json!({"command": "shape.polygon", "params": {"cx": 150, "cy": 150, "radius": 60, "sides": 5}})).unwrap();
let st = h.session.doc().unwrap();
let (uid, id) = (st.uid, st.selection.objects[0]);
let b = st.doc.node(id).unwrap().geometric_bounds_with(&st.doc.symbol_boxes()).expect("bounds");
let bx = vectorcraft_doc::OrientedBox::aligned(b);
let w = vectorcraft_tools::sidewidget::SideWidget::of(&st.doc, &st.selection, &bx, h.view.zoom).expect("a side widget");
let steps = st.history.undo.len();
let zoom = h.view.zoom;
let ev = |kind: &str, dy: f64| json!({"kind": kind, "x": w.at.x, "y": w.at.y + dy / zoom});
// The drag stays held: no `up`.
ok(&mut h, "pointer_gesture", json!({"tool": "selection", "events": [ev("down", 0.0), ev("drag", 13.0), ev("drag", 25.0)]}));
let batch = json!({"commands": [
{"command": "shape.rectangle", "params": {"x": 10, "y": 10, "width": 20, "height": 20}},
{"command": "document.activate", "params": {"index": 0}}
]});
h.call("engine.execute", json!({"command": "command.batch", "params": batch})).unwrap();
let st = h.session.documents().iter().find(|d| d.uid == uid).expect("the polygon's document");
let vectorcraft_doc::NodeKind::Path { live, .. } = &st.doc.node(id).unwrap().kind else { panic!("not a path") };
assert!(matches!(live.as_deref(), Some(vectorcraft_doc::LiveShape::Polygon { sides: 7, .. })), "the settled drag: {live:?}");
assert_eq!(st.history.undo.len(), steps + 2, "the drag and the batch, each one undo step");
let rect = st.selection.objects[0];
assert_ne!(rect, id, "the batch's rectangle is selected");
assert!(st.doc.node(rect).is_some(), "the batch's rectangle stays");
}