Keep canvas brush drops in their source document

This commit is contained in:
dotCooCoo committed 2026-11-26 09:13:17 -08:00
1 parent f040538a39
commit 68f2230d1e
2 files changed
+31 -2

No files matched your search

+5 -2
View File
@@ -173,7 +173,9 @@ impl Component for CanvasDrops<'_> {
let panel = Target::new(rect, view, covered, |p: &PanelDrag| (!matches!(p, PanelDrag::Art { .. })).then(|| Payload::Panel(p.clone())));
let style = Target::new(rect, view, covered, |d: &ListDrag<StyleKey>| Some(Payload::Style(d.grabbed.clone())));
let symbol = Target::new(rect, view, covered, |d: &ListDrag<SymbolKey>| Some(Payload::Symbol(d.grabbed.clone())));
let brush = Target::new(rect, view, covered, |d: &ListDrag<BrushKey>| Some(Payload::Brush(d.grabbed.clone())));
let brush = Target::new(rect, view, covered, |d: &ListDrag<BrushKey>| {
(d.grabbed.doc == self.document).then(|| Payload::Brush(d.grabbed.clone()))
});
let library = Target::new(rect, view, covered, |d: &ListDrag<LibraryKey>| Some(Payload::Library(d.grabbed.clone())));
let panel = cx.drop_target::<PanelDrag, _>(&panel);
let style = cx.drop_target::<ListDrag<StyleKey>, _>(&style);
@@ -336,7 +338,7 @@ pub(crate) fn apply_drop(app: &mut VectorcraftApp, drop: &Dropped) -> Result<(),
Payload::Panel(PanelDrag::LibraryGraphic { library, item }) => {
run(app, "library.use", json!({"library": library, "kind": "graphic", "item": item, "center": [at.x, at.y]}))
}
Payload::Brush(key) => match hit() {
Payload::Brush(key) if app.session.active().is_some_and(|st| st.uid == key.doc) => match hit() {
None if brush_has_art(app, key) => run(app, "brush.placeArt", json!({"name": key.name, "x": at.x, "y": at.y})),
None => Ok(()),
Some(hit) => {
@@ -344,6 +346,7 @@ pub(crate) fn apply_drop(app: &mut VectorcraftApp, drop: &Dropped) -> Result<(),
run(app, "brush.apply", json!({"name": key.name, "ids": [owner]}))
}
},
Payload::Brush(_) => Ok(()),
Payload::Style(key) => {
let Some(hit) = hit() else { return Ok(()) };
let top = top_object(app, &hit)?;
+26
View File
@@ -134,6 +134,32 @@ fn a_drop_runs_the_effect_of_its_payload() {
symbol_at(&app, empty);
}
#[test]
fn a_foreign_brush_drop_never_applies_or_places_a_same_named_brush() {
let (mut app, ctx) = app_with_canvas();
let make_brush = |app: &mut VectorcraftApp, width| {
app.run("shape.rectangle", json!({"x": 15, "y": 15, "width": width, "height": 30})).unwrap();
app.run("brush.new", json!({"name": "Shared Brush", "type": "art"})).unwrap();
};
make_brush(&mut app, 30);
let document = app.session.active().unwrap().uid;
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
make_brush(&mut app, 60);
app.run("brush.setCurrent", json!({"name": null})).unwrap();
let path = NodeId(app.run("path.create", json!({"anchors": [{"x": 50, "y": 200}, {"x": 350, "y": 200}]})).unwrap()["id"].as_u64().unwrap());
frame(&mut app, &ctx, vec![]);
let brush_of = |app: &VectorcraftApp| app.session.active().unwrap().doc.node(path).unwrap().appearance.stroke().and_then(|s| s.brush.clone());
let before = brush_of(&app);
assert!(before.is_none());
let history = undo_len(&app);
let payload = Payload::Brush(BrushKey { doc: document, name: "Shared Brush".into(), group: false });
drop_at(&mut app, payload.clone(), Point::new(200.0, 200.0), DropOperation::Move).unwrap();
assert_eq!(brush_of(&app), before, "the foreign drop leaves the path's stroke alone");
drop_at(&mut app, payload, Point::new(200.0, 260.0), DropOperation::Move).unwrap();
assert_eq!(undo_len(&app), history, "no artwork is placed on empty canvas either");
}
/// A symbol of another document is added here and placed in one undo step, the source is unchanged, and a symbol of
/// a closed document places nothing.
#[test]