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.
This commit is contained in:
dotCooCoo committed 2026-11-28 13:19:16 -08:00
1 parent 170d491cb9
commit d1dddd934a
2 files changed
+23 -3

No files matched your search

+3 -2
View File
@@ -643,8 +643,9 @@ fn move_handles(s: &mut Session, p: &Value) -> Result<Value> {
}
// 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<Value> {
.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();
}
}
+20 -1
View File
@@ -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");
}