Paste: a pasted clipping path is an ordinary path (#9227)

A copy of a clip group's clipping path kept its clipping mark when pasted
outside the group, so Offset Path and the other path commands skipped it
and Offset Path's OK did nothing. Paste now clears the mark, and Release
Clipping Mask clears it on a selected path that clips nothing, which
repairs paths pasted before this fix.
This commit is contained in:
HassanKhan committed 2026-11-27 13:24:20 +05:00
1 parent 97da102592
commit ea9cd206f6
4 files changed
+87 -2

No files matched your search

+5
View File
@@ -1592,6 +1592,11 @@ fn paste_clip(s: &mut Session, p: &Value, mode: PasteMode, clip: &Clipboard, cho
for xf in placements {
for (k, n) in clip.nodes.iter().enumerate() {
let mut c = d.reid(n);
// A pasted object never goes in as a clip group's clipping path, so a copied clipping
// path comes back as an ordinary path that the path commands work on (#9227).
if let NodeKind::Path { clipping, .. } = &mut c.kind {
*clipping = false;
}
// A pasted symbol set packs from the density recorded for it at Copy.
d.carry_set_densities(n, &c, &clip.set_densities);
imported.apply(&mut c, d);
+15 -2
View File
@@ -194,13 +194,19 @@ pub(super) fn clip_make(s: &mut Session, _: &Value) -> Result<Value> {
pub(super) fn clip_release(s: &mut Session, _: &Value) -> Result<Value> {
let ids = selected_roots(s)?;
// With no clip group selected, the document and its undo history stay as they are.
// With no clip group and no stray clipping path selected, the document and its undo history
// stay as they are.
let d = &s.doc()?.doc;
if !ids.iter().any(|id| d.node(*id).is_some_and(Node::clips)) {
if !ids.iter().any(|id| d.node(*id).is_some_and(Node::clips) || stray_clipping_path(d, *id)) {
return ok();
}
s.edit("Release Clipping Mask", |d, _| {
for id in &ids {
if stray_clipping_path(d, *id)
&& let Some(NodeKind::Path { clipping, .. }) = d.node_mut(*id).map(|n| &mut n.kind)
{
*clipping = false;
}
release_clip(d, *id);
}
Ok(())
@@ -208,6 +214,13 @@ pub(super) fn clip_release(s: &mut Session, _: &Value) -> Result<Value> {
ok()
}
/// Whether `id` is a path marked as a clipping path that clips nothing: not the bottom child of a
/// clip group or clipping layer. A paste made one before #9227; the path commands skip it.
fn stray_clipping_path(d: &Document, id: NodeId) -> bool {
let marked = d.node(id).is_some_and(|n| matches!(n.kind, NodeKind::Path { clipping: true, .. }));
marked && !d.position(id).is_some_and(|(parent, i, _)| i == 0 && parent.and_then(|p| d.node(p)).is_some_and(Node::clips))
}
/// Selects the clipping path (`mask`) or the clipped contents of every selected clip group (or of the
/// clip group containing a selected object), like Illustrator's Edit Contents / Edit Clipping Path toggle.
pub(super) fn clip_edit(s: &mut Session, mask: bool) -> Result<Value> {
+1
View File
@@ -26,6 +26,7 @@ mod lossy_overwrite;
mod model_based;
mod param_keys;
mod paste_many;
mod pasted_clipping_path;
mod pen_click_after_smooth;
mod pen_endpoint_picking;
mod pen_rubber_band;
@@ -0,0 +1,66 @@
//! A copy of a clip group's clipping path pasted outside it is an ordinary path (#9227).
use std::sync::Arc;
use serde_json::{Value, json};
use vectorcraft_doc::{NodeId, NodeKind};
use vectorcraft_engine::Session;
fn run(s: &mut Session, command: &str, params: Value) -> Value {
s.execute(command, &params).unwrap()
}
fn rect(s: &mut Session, x: f64, y: f64, w: f64, h: f64) -> NodeId {
NodeId(run(s, "shape.rectangle", json!({"x": x, "y": y, "width": w, "height": h}))["id"].as_u64().unwrap())
}
fn clipping(s: &Session, id: NodeId) -> bool {
matches!(s.doc().unwrap().doc.node(id).unwrap().kind, NodeKind::Path { clipping: true, .. })
}
/// A rectangle clipped by a smaller one, and the clipping path's id.
fn clip_group(s: &mut Session) -> NodeId {
run(s, "file.new", json!({"width": 400, "height": 400}));
let art = rect(s, 20.0, 20.0, 200.0, 200.0);
let mask = rect(s, 60.0, 60.0, 100.0, 100.0);
run(s, "select.set", json!({"ids": [art.0, mask.0]}));
run(s, "object.clippingMask.make", json!({}));
assert!(clipping(s, mask));
mask
}
#[test]
fn offset_path_offsets_a_pasted_copy_of_a_clipping_path() {
let mut s = Session::new();
let mask = clip_group(&mut s);
run(&mut s, "select.set", json!({"ids": [mask.0]}));
run(&mut s, "edit.copy", json!({}));
run(&mut s, "select.none", json!({}));
let pasted = run(&mut s, "edit.pasteInPlace", json!({}));
let copy = NodeId(pasted["ids"][0].as_u64().unwrap());
assert!(!clipping(&s, copy), "the pasted copy clips nothing, so it is not a clipping path");
assert!(clipping(&s, mask), "the original still clips its group");
run(&mut s, "select.set", json!({"ids": [copy.0]}));
let out = s.execute("object.path.offsetPath", &json!({"offset": 5}));
assert!(out.is_ok(), "Offset Path refuses the pasted copy: {out:?}");
}
#[test]
fn release_makes_a_lone_clipping_path_an_ordinary_path() {
let mut s = Session::new();
run(&mut s, "file.new", json!({"width": 400, "height": 400}));
let lone = rect(&mut s, 60.0, 60.0, 100.0, 100.0);
// As a paste made one before #9227, in a document saved then: flagged, outside any clip group.
let d = Arc::make_mut(&mut s.doc_mut().unwrap().doc);
if let NodeKind::Path { clipping, .. } = &mut d.node_mut(lone).unwrap().kind {
*clipping = true;
}
run(&mut s, "select.set", json!({"ids": [lone.0]}));
assert!(s.execute("object.path.offsetPath", &json!({"offset": 5})).is_err(), "the flagged path is skipped");
run(&mut s, "object.clippingMask.release", json!({}));
assert!(!clipping(&s, lone));
let out = s.execute("object.path.offsetPath", &json!({"offset": 5}));
assert!(out.is_ok(), "Offset Path refuses the released path: {out:?}");
}