From d1dddd934a8042a9d50abf368b160f1337b52061 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 13:16:50 -0800 Subject: [PATCH] Direct Selection: a move by nothing leaves a live shape that needs no change live path.moveHandles with dx and dy of 0 only changes anchors that become corners (both handles listed, or `independent`). It still passed every listed handle on to the edit, so a live shape whose listed anchor needed no change was expanded to a plain path. The listed anchors that need no change are now left out, and the command returns without an edit when none is left. Follows #9921, which added path.moveHandles. --- crates/engine/src/cmd/path.rs | 5 +++-- crates/engine/tests/it/several_handles.rs | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/path.rs b/crates/engine/src/cmd/path.rs index efcd2b1e13..638517aec9 100644 --- a/crates/engine/src/cmd/path.rs +++ b/crates/engine/src/cmd/path.rs @@ -643,8 +643,9 @@ fn move_handles(s: &mut Session, p: &Value) -> Result { } // A move by nothing changes only the kind of anchors that become corners: those with both // handles listed, or every listed one with `independent`. + // The other anchors are left out, so a live shape that only they lie on is not expanded. if d == Vec2::ZERO { - let corners = anchors.iter().any(|(&(id, si, ai), &(inn, out))| { + anchors.retain(|&(id, si, ai), &mut (inn, out)| { (independent || (inn && out)) && doc .node(id) @@ -652,7 +653,7 @@ fn move_handles(s: &mut Session, p: &Value) -> Result { .and_then(|pd| pd.subpaths.get(si)?.anchors.get(ai)) .is_some_and(|a| a.kind != AnchorKind::Corner) }); - if !corners { + if anchors.is_empty() { return ok(); } } diff --git a/crates/engine/tests/it/several_handles.rs b/crates/engine/tests/it/several_handles.rs index b45b6b16b6..7b5469c278 100644 --- a/crates/engine/tests/it/several_handles.rs +++ b/crates/engine/tests/it/several_handles.rs @@ -1,7 +1,7 @@ //! Direct Selection picks several direction handles and drags them together (`path.moveHandles`). use serde_json::{Value, json}; -use vectorcraft_doc::NodeId; +use vectorcraft_doc::{NodeId, NodeKind}; use vectorcraft_engine::{Session, ViewInfo}; use vectorcraft_geom::{Anchor, AnchorKind, Point}; use vectorcraft_tools::{Mods, PointerEvent, PointerKind, ToolKey}; @@ -191,3 +191,22 @@ fn move_handles_checks_its_params() { near(anchor(&s, id, 2).h_in, Point::new(305.0, 140.0)); assert_eq!(undo_len(&s), undo + 1); } + +/// A move by nothing that makes one path's smooth anchor a corner leaves a listed handle of a live +/// rectangle, which needs no change, alone: the rectangle stays live. +#[test] +fn a_move_by_nothing_leaves_a_live_shape_that_needs_no_change_live() { + let (mut s, id) = session(); + let rect = s.execute("shape.rectangle", &json!({"x": 500, "y": 400, "width": 100, "height": 60})).unwrap(); + let rect = NodeId(rect["id"].as_u64().unwrap()); + let live = |s: &Session| matches!(&s.doc().unwrap().doc.node(rect).unwrap().kind, NodeKind::Path { live: Some(_), .. }); + assert!(live(&s), "shape.rectangle makes a live rectangle"); + let handles = json!([ + {"id": id.0, "anchor": 1, "which": "in"}, + {"id": id.0, "anchor": 1, "which": "out"}, + {"id": rect.0, "anchor": 0, "which": "out"} + ]); + s.execute("path.moveHandles", &json!({"handles": handles, "dx": 0, "dy": 0})).unwrap(); + assert_eq!(anchor(&s, id, 1).kind, AnchorKind::Corner, "both handles listed make the smooth anchor a corner"); + assert!(live(&s), "the rectangle's listed handle needed no change, so the rectangle stays live"); +}