Keep linked Fill and Stroke swatch drops in their source drawing

This commit is contained in:
dotCooCoo committed 2026-11-26 18:49:48 -08:00
1 parent 0aea8fed95
commit f59cb4fa9b
1 file changed
+56 -1
+56 -1
View File
@@ -790,7 +790,17 @@ fn takes_drop(mixed: (bool, bool), well: Well, drag: &PanelDrag) -> bool {
/// Paints the fill (the primary well) or the stroke with the paint `drag` carries.
fn drop_paint(app: &mut VectorcraftApp, well: Well, drag: &PanelDrag) {
if let Some(params) = drag.paint_drop_params(app.session.active().map(|st| st.uid)) {
let destination = app.session.active().map(|st| st.uid);
if let PanelDrag::Paint { paint, rows: Some(rows), .. } = drag
&& !rows.unlinked_process_color
&& destination.is_some_and(|uid| uid != rows.document)
&& paint.color().is_some()
&& !paint.is_registration()
{
app.status(tl!("A linked color swatch can only be applied in its own document."));
return;
}
if let Some(params) = drag.paint_drop_params(destination) {
let cmd = if well == Well::Primary { "paint.setFill" } else { "paint.setStroke" };
app.run(cmd, params).ok();
}
@@ -1112,6 +1122,51 @@ mod tests {
assert_eq!(app.session.active().unwrap().doc.swatch(name).unwrap().paint, destination);
}
#[test]
fn proxy_linked_swatches_stay_in_their_source_drawing() {
use crate::panel_drag::SwatchRows;
let name = "Shared Swatch";
for spot in [false, true] {
for (different_drawing, collision) in [(false, false), (true, false), (true, true)] {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
app.run("swatch.new", json!({"name": name, "color": "#ff0000", "global": true, "spot": spot})).unwrap();
let source = app.session.active().unwrap();
let paint = source.doc.swatch(name).unwrap().paint.clone();
let rows =
SwatchRows { document: source.uid, grabbed: name.into(), names: vec![name.into()], groups: false, unlinked_process_color: false };
let drag = PanelDrag::Paint { paint, params: json!({"swatch": name}), rows: Some(rows), library: None };
if different_drawing {
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
}
if collision {
app.run("swatch.new", json!({"name": name, "color": "#0000ff", "global": true})).unwrap();
}
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 40})).unwrap();
app.run("paint.setFill", json!({"color": "#00ff00"})).unwrap();
app.run("paint.setStroke", json!({"color": "#ffff00"})).unwrap();
let initial = current_paints(&app);
let target = app.session.active().unwrap();
let palette = target.doc.swatch(name).map(|swatch| swatch.paint.clone());
let initial_undo = target.history.undo.len();
drop_paint(&mut app, Well::Primary, &drag);
drop_paint(&mut app, Well::Secondary, &drag);
let target = app.session.active().unwrap();
assert_eq!(target.doc.swatch(name).map(|swatch| swatch.paint.clone()), palette);
if different_drawing {
assert_eq!(current_paints(&app), initial, "spot={spot}, collision={collision}");
assert_eq!(target.history.undo.len(), initial_undo);
assert_eq!(app.ui.status, tl!("A linked color swatch can only be applied in its own document."));
} else {
let linked = target.doc.tint_paint(name, 1.0).unwrap();
assert_eq!(current_paints(&app), (linked.clone(), linked));
}
}
}
}
#[test]
fn paint_params_roundtrip_shapes() {
assert_eq!(paint_params(&Paint::None), json!({"none": true}));