Drag and drop: panel drags held across File › Revert are not dropped on the restored drawing

#9931 refused an appearance carried across File › Revert. Graphic styles,
brushes, symbols, swatch rows and appearance stack rows had the same fault:
a held drag still resolved a name or id against the restored contents.

- Graphic style, brush, symbol and swatch drags carry the document's revert
  count, and the canvas, the panels, the Fill/Stroke wells and the Gradient
  slider refuse a drag from before the revert.
- The Brushes panel shows no reorder marker for a stale brush drag.
- docs/mcp.md says which drops File › Revert cancels.

Follows #9931 by @dotCooCoo.
This commit is contained in:
dotCooCoo committed 2026-11-28 19:41:34 -08:00
1 parent e0649cf32f
commit 3381168a7e
15 files changed
+384 -67

No files matched your search

+22 -9
View File
@@ -120,9 +120,11 @@ pub(crate) struct CanvasDrops<'a> {
kind: BodyKind,
/// The uid of the document the canvas shows.
document: u64,
/// The revert count of the document the canvas shows: an appearance dragged from contents File › Revert replaced is
/// refused.
/// The revert count of the document the canvas shows: an appearance, graphic style or brush dragged from contents
/// File › Revert replaced is refused.
reverts: u64,
/// `(uid, reverts)` of every open document: a symbol dragged from contents File › Revert replaced is refused.
contents: Vec<(u64, u64)>,
/// `(uid, revision)` of every open document: carried art whose source is not listed unchanged is refused.
sources: Vec<(u64, u64)>,
/// Whether the art being carried is taken though its source's revision moved: its move was given up and the source
@@ -176,12 +178,17 @@ impl Component for CanvasDrops<'_> {
let panel = Target::new(rect, view, covered, |p: &PanelDrag| match p {
PanelDrag::Art { .. } => None,
PanelDrag::Appearance { .. } if p.appearance_for(self.document, self.reverts).is_none() => None,
_ if p.stale_rows(Some((self.document, self.reverts))) => None,
_ => Some(Payload::Panel(p.clone())),
});
let style = Target::new(rect, view, covered, |d: &StyleDrag| (d.document == self.document).then(|| Payload::Style(d.clone())));
let symbol = Target::new(rect, view, covered, |d: &ListDrag<SymbolKey>| Some(Payload::Symbol(d.grabbed.clone())));
let here = (self.document, self.reverts);
let style = Target::new(rect, view, covered, |d: &StyleDrag| ((d.document, d.reverts) == here).then(|| Payload::Style(d.clone())));
// A symbol of any open document's current contents.
let symbol = Target::new(rect, view, covered, |d: &ListDrag<SymbolKey>| {
self.contents.contains(&(d.grabbed.doc, d.grabbed.reverts)).then(|| Payload::Symbol(d.grabbed.clone()))
});
let brush = Target::new(rect, view, covered, |d: &ListDrag<BrushKey>| {
(d.grabbed.doc == self.document).then(|| Payload::Brush(d.grabbed.clone()))
((d.grabbed.doc, d.grabbed.reverts) == here).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);
@@ -222,6 +229,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut Ui, win: Win, kind: BodyKi
BodyKind::Pane => pane_view(app, win, rect),
};
let (Some(view), Some((document, reverts))) = (view, app.session.documents().get(win.0).map(|d| (d.uid, d.reverts))) else { return };
let contents = app.session.documents().iter().map(|d| (d.uid, d.reverts)).collect();
let sources = app.session.documents().iter().map(|d| (d.uid, d.revision)).chain(app.canvas.panes.released_from).collect();
// A tab rest leaves the art to the document it showed while that is the current one: any canvas or pane takes it
// then, and nothing once that document was closed or left by other means.
@@ -234,7 +242,8 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut Ui, win: Win, kind: BodyKi
let ctx = ui.ctx().clone();
let covered = |at: Pos2| crate::panel_docking::os_window_at(app, &ctx, at);
let files = (CanvasFiles::new(app, rect, &view), &files_out);
let drops = CanvasDrops { common: Common::new(), view, kind, document, reverts, sources, given_up, covered: &covered, out: &out, files };
let drops =
CanvasDrops { common: Common::new(), view, kind, document, reverts, contents, sources, given_up, covered: &covered, out: &out, files };
drops.id_salt(("canvas-drops", win)).show_at(ui, rect);
if let Some(files) = files_out.take() {
crate::place::canvas_drop(app, ui.ctx(), files);
@@ -330,6 +339,8 @@ pub(crate) fn apply_drop(app: &mut VectorcraftApp, drop: &Dropped) -> Result<(),
)
}
}
// A symbol of contents File › Revert replaced places nothing.
Payload::Symbol(key) if !app.session.documents().iter().any(|d| (d.uid, d.reverts) == (key.doc, key.reverts)) => Ok(()),
Payload::Symbol(key) => run(app, "symbol.placeFromDocument", json!({"sourceDocument": key.doc, "name": key.name, "x": at.x, "y": at.y})),
Payload::Library(key) if key.folder => Ok(()),
Payload::Library(key) => match library_panel::parse(&key.panel) {
@@ -346,7 +357,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) if app.session.active().is_some_and(|st| st.uid == key.doc) => match hit() {
Payload::Brush(key) if app.session.active().is_some_and(|st| (st.uid, st.reverts) == (key.doc, key.reverts)) => match hit() {
None if brush_has_art(app, key) && no_art_at(app, at, zoom) => {
run(app, "brush.placeArt", json!({"name": key.name, "x": at.x, "y": at.y}))
}
@@ -357,12 +368,14 @@ pub(crate) fn apply_drop(app: &mut VectorcraftApp, drop: &Dropped) -> Result<(),
}
},
Payload::Brush(_) => Ok(()),
Payload::Style(style) if app.session.active().is_some_and(|st| st.uid == style.document) => {
Payload::Style(style) if app.session.active().is_some_and(|st| (st.uid, st.reverts) == (style.document, style.reverts)) => {
let Some(hit) = hit() else { return Ok(()) };
let top = top_object(app, &hit)?;
run(app, "graphicStyle.apply", json!({"name": style.name, "ids": [top], "add": drop.op == DropOperation::Copy}))
}
Payload::Style(_) => Ok(()),
// Swatch rows of contents File › Revert replaced apply and place nothing.
Payload::Panel(drag @ PanelDrag::Paint { .. }) if drag.stale_rows(app.session.active().map(|st| (st.uid, st.reverts))) => Ok(()),
// A pattern swatch from the Swatches panel dropped where there is no art: a copy of its tile art with its tile.
Payload::Panel(PanelDrag::Paint { paint: vectorcraft_color::Paint::Pattern { pattern, .. }, rows: Some(_), .. })
if hit().is_none() && no_art_at(app, at, zoom) =>
@@ -385,7 +398,7 @@ pub(crate) fn apply_drop(app: &mut VectorcraftApp, drop: &Dropped) -> Result<(),
{
return Err(tl!("A linked color swatch can only be applied in its own document.").into());
}
let Some(mut params) = drag.paint_drop_params(destination) else { return Ok(()) };
let Some(mut params) = drag.paint_drop_params(app.session.active().map(|st| (st.uid, st.reverts))) else { return Ok(()) };
params["ids"] = json!([owner(app, &hit)?]);
params["focus"] = json!(false);
let cmd = crate::panels::proxy_cmd(app, false);
+101 -10
View File
@@ -68,7 +68,7 @@ fn a_foreign_graphic_style_drop_does_not_apply_a_style_with_the_same_name() {
let before = fill(&app);
let history = undo_len(&app);
let at = Point::new(250.0, 70.0);
let payload = Payload::Style(StyleDrag { document, name: "Shared name".into() });
let payload = Payload::Style(StyleDrag { document, reverts: 0, name: "Shared name".into() });
for operation in [DropOperation::Move, DropOperation::Copy] {
drop_at(&mut app, payload.clone(), at, operation).unwrap();
assert_eq!(fill(&app), before);
@@ -135,7 +135,7 @@ fn a_drop_runs_the_effect_of_its_payload() {
assert_eq!(app.session.active().unwrap().selection.objects, [a], "the selection stays");
let st = app.session.active().unwrap();
let name = st.doc.graphic_styles[2].name.clone();
let style = Payload::Style(StyleDrag { document: st.uid, name: name.clone() });
let style = Payload::Style(StyleDrag { document: st.uid, reverts: st.reverts, name: name.clone() });
drop_at(&mut app, style.clone(), on_b, Move).unwrap();
let st = app.session.active().unwrap();
assert_eq!(st.doc.node(b).unwrap().extras().graphic_style, st.doc.graphic_style(&name).map(|g| g.id));
@@ -165,7 +165,7 @@ fn a_drop_runs_the_effect_of_its_payload() {
let path = NodeId(app.run("path.create", json!({"anchors": [{"x": 50, "y": 200}, {"x": 350, "y": 200}]})).unwrap()["id"].as_u64().unwrap());
let brush_of = |app: &VectorcraftApp| app.session.active().unwrap().doc.node(path).unwrap().appearance.stroke().and_then(|s| s.brush.clone());
let uid = app.session.active().unwrap().uid;
let brush = |name: &str| Payload::Brush(BrushKey { doc: uid, name: name.into(), group: false });
let brush = |name: &str| Payload::Brush(BrushKey { doc: uid, reverts: 0, name: name.into(), group: false });
let library = |kind: &str, id: &str, name: &str| {
Payload::Library(LibraryKey { panel: library_panel::panel_id(kind, id), name: name.into(), folder: false })
};
@@ -200,7 +200,7 @@ fn a_drop_runs_the_effect_of_its_payload() {
drop_at(&mut app, library(SymbolLibraries::KIND, "basic-shapes", "Star"), on_b, Move).unwrap();
assert_eq!(undo_len(&app), n + 1, "a library symbol is added and placed in one step");
symbol_at(&app, on_b);
drop_at(&mut app, Payload::Symbol(SymbolKey { doc: uid, name: "Star".into() }), empty, Move).unwrap();
drop_at(&mut app, Payload::Symbol(SymbolKey { doc: uid, reverts: 0, name: "Star".into() }), empty, Move).unwrap();
symbol_at(&app, empty);
}
@@ -215,8 +215,13 @@ fn a_brush_with_art_dropped_inside_a_fill_with_path_only_places_nothing() {
app.run("prefs.set", json!({"key": "objectSelectionByPathOnly", "value": true})).unwrap();
let uid = app.session.active().unwrap().uid;
let n = undo_len(&app);
drop_at(&mut app, Payload::Brush(BrushKey { doc: uid, name: "Arrow".into(), group: false }), Point::new(300.0, 240.0), DropOperation::Move)
.unwrap();
drop_at(
&mut app,
Payload::Brush(BrushKey { doc: uid, reverts: 0, name: "Arrow".into(), group: false }),
Point::new(300.0, 240.0),
DropOperation::Move,
)
.unwrap();
assert_eq!(undo_len(&app), n, "{}", app.ui.status);
}
@@ -233,7 +238,7 @@ fn a_pattern_swatch_dropped_off_the_art_places_a_copy_of_its_tile_art_there() {
app.run("select.none", json!({})).unwrap();
let document = app.session.active().unwrap().uid;
let swatch = |name: &str, paint: Paint| {
let rows = SwatchRows { document, grabbed: name.into(), names: vec![name.into()], groups: false, unlinked_process_color: false };
let rows = SwatchRows { document, reverts: 0, grabbed: name.into(), names: vec![name.into()], groups: false, unlinked_process_color: false };
Payload::Panel(PanelDrag::Paint { paint, params: json!({"swatch": name}), rows: Some(rows), library: None })
};
let pattern = swatch("Checks", vectorcraft_doc::pattern::pattern_paint("Checks"));
@@ -281,7 +286,7 @@ fn a_foreign_brush_drop_never_applies_or_places_a_same_named_brush() {
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 });
let payload = Payload::Brush(BrushKey { doc: document, reverts: 0, 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();
@@ -301,7 +306,7 @@ fn a_symbol_from_another_document_is_added_and_placed_in_one_step() {
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
let ctx = crate::testing::ui_context();
frame(&mut app, &ctx, vec![]);
let key = |doc| Payload::Symbol(SymbolKey { doc, name: "Leaf".into() });
let key = |doc| Payload::Symbol(SymbolKey { doc, reverts: 0, name: "Leaf".into() });
let at = Point::new(250.0, 180.0);
let n = undo_len(&app);
drop_at(&mut app, key(source), at, DropOperation::Move).unwrap();
@@ -329,7 +334,14 @@ fn a_process_swatch_canvas_drop_keeps_its_color_in_another_document() {
app.run("swatch.new", json!({"name": name, "color": "#ff0000"})).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: true };
let rows = SwatchRows {
document: source.uid,
reverts: source.reverts,
grabbed: name.into(),
names: vec![name.into()],
groups: false,
unlinked_process_color: true,
};
let payload = PanelDrag::Paint { paint: paint.clone(), params: json!({"swatch": name}), rows: Some(rows), library: None };
let local_target = add_target(&mut app);
@@ -720,3 +732,82 @@ fn an_appearance_drop_after_file_revert_leaves_the_restored_object_unchanged() {
panel.release();
assert_eq!(fill(&panel.app()), red, "a drag started after the revert copies the appearance");
}
/// A graphic style, brush or symbol held across File › Revert, released on art on the canvas, makes no edit to the
/// restored contents, both where the canvas takes the drop and where the drop is applied. The same drag started after
/// the revert still applies or places it.
#[test]
fn a_style_brush_or_symbol_held_across_file_revert_is_not_dropped_on_the_canvas() {
use crate::tests::panel_harness::Panel;
use craft::ui::runtime::drag;
fn beside_canvas(app: &mut VectorcraftApp, ui: &mut egui::Ui, panel: fn(&mut VectorcraftApp, &mut egui::Ui)) {
app.sync_views();
egui::Panel::top("source panel").exact_size(220.0).show(ui, |ui| panel(app, ui));
canvas::show(app, ui);
}
fn styles(app: &mut VectorcraftApp, ui: &mut egui::Ui) {
beside_canvas(app, ui, crate::panels::graphic_styles::show);
}
fn brushes(app: &mut VectorcraftApp, ui: &mut egui::Ui) {
beside_canvas(app, ui, crate::panels::brushes::show);
}
fn symbols(app: &mut VectorcraftApp, ui: &mut egui::Ui) {
beside_canvas(app, ui, crate::panels::symbols::show);
}
type Show = fn(&mut VectorcraftApp, &mut egui::Ui);
let panels: [(&str, Show); 3] = [("style", styles), ("brush", brushes), ("symbol", symbols)];
for (kind, show) in panels {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|e| e.to_string())));
app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|e| e.to_string())));
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
app.run("shape.rectangle", json!({"x": 20, "y": 20, "width": 40, "height": 30})).unwrap();
app.run("paint.setFill", json!({"color": "#00ff00"})).unwrap();
match kind {
"style" => app.run("graphicStyle.new", json!({"name": "Held"})).map(drop),
"brush" => app
.run("brush.new", json!({"name": "Held", "type": "art"}))
.and_then(|_| app.run("brush.setCurrent", json!({"name": null})).map(drop)),
_ => app.run("symbol.new", json!({"name": "Held"})).map(drop),
}
.unwrap();
app.run("path.create", json!({"anchors": [{"x": 200, "y": 150}, {"x": 380, "y": 150}]})).unwrap();
app.run("select.none", json!({})).unwrap();
let folder = vectorcraft_testkit::TempDir::new("canvas-panel-item-drop-revert");
let path = folder.join("drawing.vectorcraft");
app.run("file.saveAs", json!({"path": path.to_string_lossy()})).unwrap();
app.run("shape.ellipse", json!({"x": 20, "y": 250, "width": 20, "height": 20})).unwrap();
app.run("select.none", json!({})).unwrap();
let mut panel = Panel::new(app, show);
let hold = |panel: &mut Panel| {
let from = panel.rect("Held").center();
let to = panel.app().canvas_view().unwrap().to_screen(Point::new(290.0, 150.0));
panel.drag_hold_between(from, to);
};
hold(&mut panel);
assert!(drag::mark(panel.ctx()).is_some(), "{kind}: the canvas takes it from the current contents");
let opening = panel.app().session.active().map(|st| (st.uid, st.reverts)).unwrap();
panel.app().run("file.revert", json!({"confirmed": true})).unwrap();
panel.frame();
assert_eq!(panel.app().session.active().map(|st| (st.uid, st.reverts)), Some((opening.0, opening.1 + 1)));
let history = undo_len(&panel.app());
assert!(drag::mark(panel.ctx()).is_none(), "{kind}: the canvas refuses it once the contents it came from are gone");
panel.release();
assert_eq!(undo_len(&panel.app()), history, "{kind}: the stale drop makes no edit");
let stale = match kind {
"style" => Payload::Style(StyleDrag { document: opening.0, reverts: opening.1, name: "Held".into() }),
"brush" => Payload::Brush(BrushKey { doc: opening.0, reverts: opening.1, name: "Held".into(), group: false }),
_ => Payload::Symbol(SymbolKey { doc: opening.0, reverts: opening.1, name: "Held".into() }),
};
drop_at(&mut panel.app(), stale, Point::new(290.0, 150.0), DropOperation::Move).unwrap();
assert_eq!(undo_len(&panel.app()), history, "{kind}: a stale payload that reaches the drop is not applied");
hold(&mut panel);
panel.release();
assert_eq!(undo_len(&panel.app()), history + 1, "{kind}: a drag started after the revert is still dropped");
}
}
+15 -2
View File
@@ -46,6 +46,8 @@ pub enum PanelDrag {
pub struct SwatchRows {
/// The document whose rows the drag started on.
pub document: u64,
/// The document's revert count: rows held across File › Revert name swatches of contents that are gone.
pub reverts: u64,
pub grabbed: String,
pub names: Vec<String>,
/// The names are colour groups.
@@ -90,13 +92,24 @@ impl PanelDrag {
}
}
/// Whether the drag carries swatch rows of `current` (`(uid, reverts)` of the active document) from before
/// File › Revert: their names may now stand for other swatches, so a drop of them applies nothing.
pub(crate) fn stale_rows(&self, current: Option<(u64, u64)>) -> bool {
matches!(self, Self::Paint { rows: Some(r), .. } if current.is_some_and(|(uid, reverts)| uid == r.document && reverts != r.reverts))
}
/// A named process swatch follows the source drawing's swatch. In another drawing its
/// captured process color applies without using a same-name swatch there.
pub(crate) fn paint_drop_params(&self, destination: Option<u64>) -> Option<Value> {
/// captured process color applies without using a same-name swatch there. Swatch rows of the destination's
/// contents from before File › Revert apply nothing.
pub(crate) fn paint_drop_params(&self, destination: Option<(u64, u64)>) -> Option<Value> {
if self.stale_rows(destination) {
return None;
}
let Self::Paint { paint, params, rows, .. } = self else { return None };
if params.is_null() {
return None;
}
let destination = destination.map(|d| d.0);
if let Some(rows) = rows.as_ref().filter(|rows| rows.unlinked_process_color)
&& destination.is_some_and(|uid| uid != rows.document)
&& let Some(color) = paint.color()
+63 -5
View File
@@ -754,12 +754,13 @@ pub(crate) fn proxy(app: &mut VectorcraftApp, ui: &mut Ui) {
};
let wells = [well(tl!("Fill"), &fill, mixed.0), well(tl!("Stroke"), &stroke, mixed.1).ring(true)];
let active = if app.session.fill_active { Well::Primary } else { Well::Secondary };
let current = app.session.active().map(|st| (st.uid, st.reverts));
let out = SwatchPair::new(tl!("Fill and Stroke"), wells, Bind::given(active))
.swap_button(tl!("Swap Fill and Stroke"))
.default_button(tl!("Default Fill and Stroke"))
.popover(false)
.drags([Some(PanelDrag::paint(fill)), Some(PanelDrag::paint(stroke))])
.accepts(move |well, drag| takes_drop(mixed, well, drag))
.accepts(move |well, drag| takes_drop(mixed, well, drag) && !drag.stale_rows(current))
.show(ui);
proxy_events(app, &out);
if let Some((well, drag)) = &out.dropped {
@@ -813,7 +814,7 @@ fn drop_paint(app: &mut VectorcraftApp, well: Well, drag: &PanelDrag) {
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) {
if let Some(params) = drag.paint_drop_params(app.session.active().map(|st| (st.uid, st.reverts))) {
let cmd = if well == Well::Primary { "paint.setFill" } else { "paint.setStroke" };
app.run(cmd, params).ok();
}
@@ -1125,6 +1126,50 @@ mod tests {
assert_eq!(current_paints(&app).0.color().map(|c| c.to_hex()), Some("#00ff00".into()));
}
/// A swatch row held across File › Revert and dropped on a Fill/Stroke well applies nothing to the restored
/// drawing; the same drop from the current contents still applies.
#[test]
fn a_proxy_drop_of_a_swatch_row_held_across_file_revert_applies_nothing() {
use crate::panel_drag::SwatchRows;
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|e| e.to_string())));
app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|e| e.to_string())));
let name = "Held Swatch";
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 40})).unwrap();
app.run("swatch.new", json!({"name": name, "color": "#ff0000"})).unwrap();
let folder = vectorcraft_testkit::TempDir::new("proxy-swatch-drop-revert");
let path = folder.join("drawing.vectorcraft");
app.run("file.saveAs", json!({"path": path.to_string_lossy()})).unwrap();
let drag = |app: &VectorcraftApp| {
let st = app.session.active().unwrap();
let paint = st.doc.swatch(name).unwrap().paint.clone();
let rows = SwatchRows {
document: st.uid,
reverts: st.reverts,
grabbed: name.into(),
names: vec![name.into()],
groups: false,
unlinked_process_color: false,
};
PanelDrag::Paint { paint, params: json!({"swatch": name}), rows: Some(rows), library: None }
};
app.run("swatch.edit", json!({"name": name, "color": "#00ff00"})).unwrap();
let held = drag(&app);
app.run("file.revert", json!({"confirmed": true})).unwrap();
app.run("select.all", json!({})).unwrap();
let before = current_paints(&app).0;
let undo = app.session.active().unwrap().history.undo.len();
drop_paint(&mut app, Well::Primary, &held);
assert_eq!(current_paints(&app).0, before, "the stale swatch row paints nothing");
assert_eq!(app.session.active().unwrap().history.undo.len(), undo, "the stale drop makes no edit");
let fresh = drag(&app);
drop_paint(&mut app, Well::Primary, &fresh);
assert_eq!(current_paints(&app).0, app.session.active().unwrap().doc.swatch(name).unwrap().paint, "a fresh drag applies");
}
#[test]
fn proxy_drops_keep_the_dragged_process_color_after_switching_documents() {
use crate::panel_drag::SwatchRows;
@@ -1136,7 +1181,14 @@ mod tests {
app.run("swatch.new", json!({"name": name, "color": "#ff0000"})).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: true };
let rows = SwatchRows {
document: source.uid,
reverts: source.reverts,
grabbed: name.into(),
names: vec![name.into()],
groups: false,
unlinked_process_color: true,
};
let drag = PanelDrag::Paint { paint: paint.clone(), params: json!({"swatch": name}), rows: Some(rows), library: None };
app.run("swatch.edit", json!({"name": name, "color": "#ff8800"})).unwrap();
drop_paint(&mut app, Well::Primary, &drag);
@@ -1164,8 +1216,14 @@ mod tests {
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 rows = SwatchRows {
document: source.uid,
reverts: source.reverts,
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();
+2 -1
View File
@@ -438,7 +438,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let order = rows.keys();
let sel = current_sel(app, node.as_deref());
let mut selection = node.as_deref().map_or_else(Selection::default, |n| list_selection(app, n, sel));
let document = app.session.active().map(|st| st.uid);
// The list is keyed by the document's contents: rows held across File › Revert name items of contents that are gone.
let document = app.session.active().map(|st| (st.uid, st.reverts));
let list_id = ui.scope_id().with(("appearance-rows", document));
let has = node.is_some();
// A dragged fill/stroke or effect row lights Duplicate and Delete up, also with nothing picked.
@@ -613,6 +613,42 @@ fn the_selection_summary_is_reused_until_the_document_or_its_subjects_change() {
assert!(fresh_summary(&mut app).mixed(&app).is_some_and(|m| !m.transparency), "the first document's again");
}
/// A fill row held across File › Revert and released on Duplicate Selected Item leaves the restored object's
/// appearance as it is; the same drag started after the revert still duplicates the row.
#[test]
fn an_appearance_row_held_across_file_revert_is_not_dropped_on_the_footer() {
use craft::ui::runtime::drag;
let mut app = app_with_a_selected_rectangle();
app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|e| e.to_string())));
app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|e| e.to_string())));
let id = app.session.active().unwrap().selection.objects[0];
let folder = vectorcraft_testkit::TempDir::new("appearance-rows-revert");
let path = folder.join("drawing.vectorcraft");
app.run("file.saveAs", json!({"path": path.to_string_lossy()})).unwrap();
app.run("paint.setFill", json!({"color": "#ff0000"})).unwrap();
let items = |panel: &Panel| node(&panel.app()).appearance.items.len();
let mut panel = Panel::new(app, show);
let hold = |panel: &mut Panel| {
let (from, to) = (panel.rect("Fill").center(), panel.rect("Duplicate Selected Item").center());
panel.drag_hold_between(from, to);
};
hold(&mut panel);
assert!(drag::mark(panel.ctx()).is_some(), "Duplicate Selected Item takes rows of the current contents");
panel.app().run("file.revert", json!({"confirmed": true})).unwrap();
panel.app().run("select.set", json!({ "ids": [id.0] })).unwrap();
panel.frame();
let before = items(&panel);
assert!(drag::mark(panel.ctx()).is_none(), "the footer refuses rows of the contents File › Revert replaced");
panel.release();
assert_eq!(items(&panel), before, "the stale row duplicates nothing");
hold(&mut panel);
panel.release();
assert_eq!(items(&panel), before + 1, "a drag started after the revert still duplicates the row");
}
/// The panel's subject is the `Arc` the document holds for the selected object, a targeted group
/// or a targeted layer, not a copy of it; nothing with nothing selected.
#[test]
+16 -10
View File
@@ -312,6 +312,8 @@ pub(crate) struct BrushesView {
pub(crate) struct BrushKey {
/// The uid of the document whose brush it is: a drag from another document's panel names another brush.
pub doc: u64,
/// The document's revert count: a drag held across File › Revert names a brush of contents that are gone.
pub reverts: u64,
/// The brush's name, or the group's type.
pub name: String,
/// Whether the row is a type's group.
@@ -319,15 +321,15 @@ pub(crate) struct BrushKey {
}
impl BrushKey {
fn brush(doc: u64, name: &str) -> Self {
Self { doc, name: name.to_string(), group: false }
fn brush((doc, reverts): (u64, u64), name: &str) -> Self {
Self { doc, reverts, name: name.to_string(), group: false }
}
}
/// The panel's rows: a group per shown type in [`KINDS`] order, without the `hidden` types, each over its brushes of
/// `shown` in library order. Of two brushes with one name only the first, the one a stroke that names it draws with,
/// has a row, so row keys stay unique.
fn rows(doc: u64, shown: &[Shown], hidden: &[String]) -> Vec<PresetRow<BrushKey>> {
fn rows(doc: (u64, u64), shown: &[Shown], hidden: &[String]) -> Vec<PresetRow<BrushKey>> {
let first = by_name(shown);
let mut rows = Vec::new();
for (ty, label) in KINDS.iter().filter(|(ty, _)| !hidden.iter().any(|h| h == ty)) {
@@ -335,7 +337,7 @@ fn rows(doc: u64, shown: &[Shown], hidden: &[String]) -> Vec<PresetRow<BrushKey>
if of_type.is_empty() {
continue;
}
rows.push(PresetRow::group(BrushKey { doc, name: ty.to_string(), group: true }, tl!(label), 0));
rows.push(PresetRow::group(BrushKey { doc: doc.0, reverts: doc.1, name: ty.to_string(), group: true }, tl!(label), 0));
rows.extend(of_type.into_iter().map(|b| PresetRow::item(BrushKey::brush(doc, &b.name), b.name.clone(), 1)));
}
rows
@@ -346,6 +348,7 @@ fn rows(doc: u64, shown: &[Shown], hidden: &[String]) -> Vec<PresetRow<BrushKey>
#[derive(MemoProps)]
struct BrushSource<'a> {
uid: u64,
reverts: u64,
revision: u64,
#[memo_props(covered_by = "revision", reason = "a document version's brushes and resources are fixed")]
doc: Option<&'a Document>,
@@ -356,8 +359,11 @@ struct BrushSource<'a> {
/// The panel's presets: [`rows`]; a brush moves only among those of its type, and paints its stroke preview.
fn brush_source(inputs: BrushSource<'_>) -> PresetSource<'_, BrushKey> {
let fns = PresetFns::<BrushSource<'_>, BrushKey>::new(|s, _| rows(s.uid, s.shown, &s.hidden))
let fns = PresetFns::<BrushSource<'_>, BrushKey>::new(|s, _| rows((s.uid, s.reverts), s.shown, &s.hidden))
.accepts(|s, drag, over, _| {
if (drag.grabbed.doc, drag.grabbed.reverts) != (s.uid, s.reverts) {
return false;
}
let first = by_name(s.shown);
over.and_then(|over| type_of(&first, over)).is_some_and(|ty| type_of(&first, &drag.grabbed) == Some(ty))
})
@@ -531,7 +537,7 @@ fn names_of(sel: &Selection<BrushKey>, doc: u64) -> Selection<String> {
}
/// The keys of the brushes `sel` names in the document `doc`.
fn keys_of(sel: &Selection<String>, doc: u64) -> Selection<BrushKey> {
fn keys_of(sel: &Selection<String>, doc: (u64, u64)) -> Selection<BrushKey> {
let key = |name: &String| BrushKey::brush(doc, name);
Selection::new(sel.items.iter().map(key).collect(), sel.lead.as_ref().map(key), sel.anchor.as_ref().map(key))
}
@@ -558,8 +564,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let sel_brush = selected_brush(app);
let highlighted = sel_brush.clone().or_else(|| current.clone());
let given = match &multi {
Some(sel) => keys_of(sel, uid),
None => highlighted.as_deref().map(|name| Selection::single(BrushKey::brush(uid, name))).unwrap_or_default(),
Some(sel) => keys_of(sel, (uid, reverts)),
None => highlighted.as_deref().map(|name| Selection::single(BrushKey::brush((uid, reverts), name))).unwrap_or_default(),
};
let hidden = app.ui.brushes_view.hidden.clone();
let view = if app.ui.brushes_view.list { PresetView::List } else { PresetView::Grid };
@@ -572,7 +578,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
};
let ctx = ui.ctx().clone();
let (doc, first, multi_ref, list_ref) = (doc.as_deref(), &first, multi.as_ref(), list.as_slice());
let source = brush_source(BrushSource { uid, revision, doc, shown: &memo, hidden: hidden.clone() });
let source = brush_source(BrushSource { uid, reverts, revision, doc, shown: &memo, hidden: hidden.clone() });
let browser = |ui: &mut Ui| {
let mut state = PresetState::new();
let ctx = ctx.clone();
@@ -639,7 +645,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
}
}
PresetEvent::Menu { target, command, .. } => item_command(app, &target, &command, multi.as_ref()),
PresetEvent::Reorder(edit) => move_brush(app, &rows(uid, &memo, &hidden), first, &edit),
PresetEvent::Reorder(edit) => move_brush(app, &rows((uid, reverts), &memo, &hidden), first, &edit),
PresetEvent::Dropped { at, payload, .. } => {
if let (DropAt::Onto(key), Some(ids)) = (&at, payload.get::<PanelDrag>().and_then(|p| art_of(p, uid, reverts))) {
crate::dialogs::brush_replace_art::replace(app, &key.name, &ids);
+4 -3
View File
@@ -533,7 +533,8 @@ fn a_brush_dragged_onto_another_of_its_type_moves_before_it() {
let mut t = Trial::new();
let app = t.app();
let st = app.session.active().unwrap();
let order: Vec<String> = rows(st.uid, &document_brushes(st), &[]).into_iter().filter(|row| !row.is_group()).map(|row| row.label).collect();
let order: Vec<String> =
rows((st.uid, st.reverts), &document_brushes(st), &[]).into_iter().filter(|row| !row.is_group()).map(|row| row.label).collect();
drop(app);
assert_eq!(order[..4], ["3 pt. Round", "6 pt. Flat", "10 pt. Oval", "Dots"]);
let undo = |t: &Trial| undo_count(&t.app());
@@ -886,8 +887,8 @@ fn rows_of_two_brushes_with_one_name_show_the_first() {
let shown = by_name(&raw)["Twin"];
assert_eq!(shown.ty, "art");
assert_eq!(shown.def, got, "the first of two rows of one name is the one shown");
let keys: Vec<BrushKey> = rows(st.uid, &raw, &[]).into_iter().filter(|row| !row.is_group()).map(|row| row.key).collect();
assert_eq!(keys, [BrushKey::brush(st.uid, "Twin")], "one row, under the first one's type");
let keys: Vec<BrushKey> = rows((st.uid, st.reverts), &raw, &[]).into_iter().filter(|row| !row.is_group()).map(|row| row.key).collect();
assert_eq!(keys, [BrushKey::brush((st.uid, st.reverts), "Twin")], "one row, under the first one's type");
}
/// A brush's menu acts on it alone, or on the multi-selection when the brush is one of several
+2
View File
@@ -846,7 +846,9 @@ fn stops_editor(app: &mut VectorcraftApp, ui: &mut Ui, g: &GradientPaint, is_gra
open_popover(app, request.index, at);
}
// A colour swatch dropped on the slider: a global or spot colour (or a tint of one) stays linked.
// Swatch rows held across File › Revert change no stop.
if let Some((place, drag)) = &out.dropped
&& !drag.stale_rows(app.session.active().map(|st| (st.uid, st.reverts)))
&& let Some(c) = drag.color()
{
let link = match drag {
+44 -8
View File
@@ -56,10 +56,11 @@ use crate::panel_drag::PanelDrag;
/// A style of the panel: its name, which is unique in a document.
pub(crate) type StyleKey = String;
/// A document's graphic style dragged out to the canvas.
/// A document's graphic style dragged out to the canvas. `reverts` identifies the contents it came from.
#[derive(Clone, Debug)]
pub(crate) struct StyleDrag {
pub(crate) document: u64,
pub(crate) reverts: u64,
pub(crate) name: StyleKey,
}
@@ -481,8 +482,9 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let (alt, linked) = (alt_held(ui), app.session.selection_graphic_style().is_some());
let thumbs = style_thumbs(app, &doc, &looks, panel.preview);
let source = style_source(thumbs);
// The browser's own state (an open rename field, the scroll position) is kept per document.
let browser_id = ui.make_persistent_id(("graphic-styles-browser", uid));
// The browser's own state (an open rename field, the scroll position) is kept per document contents: a style
// dragged from contents File › Revert replaced is not this list's.
let browser_id = ui.make_persistent_id(("graphic-styles-browser", uid, reverts));
let list = PresetBrowser::<StyleKey>::list_id(browser_id);
let takes_object = move |drag: &PanelDrag, _: &DropAt<StyleKey>| dropped_object(drag, uid, reverts).is_some();
// A style dragged from this panel's list.
@@ -524,16 +526,15 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
.selection(Bind::bound(&mut panel.selection))
.view_lock(view.preset_view())
.reorder(PresetReorder::items())
.drag_payload(move |drag: &ListDrag<StyleKey>| Some(StyleDrag { document: uid, name: drag.grabbed.clone() }))
.drag_payload(move |drag: &ListDrag<StyleKey>| Some(StyleDrag { document: uid, reverts, name: drag.grabbed.clone() }))
.empty(tl!("Select styled art and click New Graphic Style."))
.row_items(items)
.tip(|ui, key| large_tip(app, &thumbs, ui, key))
.takes_drop(PresetDrop::new::<PanelDrag>(DropPlace::Between, takes_object))
.takes_drop(PresetDrop::new::<PanelDrag>(DropPlace::Onto, takes_object))
.takes_drop(PresetDrop::new::<ListDrag<StyleKey>>(
DropPlace::Onto,
|drag, at| matches!(at, DropAt::Onto(name) if !drag.keys.contains(name)),
))
.takes_drop(PresetDrop::new::<ListDrag<StyleKey>>(DropPlace::Onto, move |drag, at| {
ours(drag) && matches!(at, DropAt::Onto(name) if !drag.keys.contains(name))
}))
.show(ui)
})
};
@@ -1612,6 +1613,41 @@ mod tests {
assert_eq!(names(&p.app()).len(), before.len() + 1, "a thumbnail drag started after the revert still makes a style");
}
/// A style of the list held across File › Revert and released on New Graphic Style duplicates no style of the
/// restored contents; the same drag started after the revert still duplicates it.
#[test]
fn a_style_held_across_file_revert_is_not_dropped_on_the_footer() {
use crate::tests::panel_harness::Panel as PanelHarness;
use craft::ui::runtime::drag;
let mut app = app();
app.run("graphicStyle.new", json!({"name": "Held"})).unwrap();
let folder = vectorcraft_testkit::TempDir::new("graphic-styles-footer-revert");
let path = folder.join("drawing.vectorcraft");
app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|err| err.to_string())));
app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|err| err.to_string())));
app.run("file.saveAs", json!({"path": path.to_string_lossy()})).unwrap();
app.run("shape.ellipse", json!({"x": 60, "y": 60, "width": 20, "height": 20})).unwrap();
let mut p = PanelHarness::new(app, show);
let hold = |p: &mut PanelHarness| {
let (from, to) = (p.rect("Held").center(), p.rect("New Graphic Style (Alt-click to name it)").center());
p.drag_hold_between(from, to);
};
hold(&mut p);
assert!(drag::mark(p.ctx()).is_some(), "New Graphic Style takes a style of the current contents");
p.app().run("file.revert", json!({"confirmed": true})).unwrap();
p.frame();
let before = names(&p.app());
assert!(drag::mark(p.ctx()).is_none(), "New Graphic Style refuses a style of the contents File › Revert replaced");
p.release();
assert_eq!(names(&p.app()), before, "the stale drop duplicates nothing");
hold(&mut p);
p.release();
assert_eq!(names(&p.app()).len(), before.len() + 1, "a drag started after the revert still duplicates the style");
}
/// A style dropped on another with Alt takes that style's look; on itself it does nothing.
#[test]
fn a_style_dropped_on_another_with_alt_replaces_that_style() {
+10 -6
View File
@@ -418,7 +418,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui) {
let state = &mut model.state;
// The browser fills the room the footer leaves, so the footer stays in view under the swatches. The body can run
// more than once in a pass, so each run builds its own browser. A list drag is keyed by its browser ID. Each
// document has its own browser.
// document's contents have their own browser, so rows held across File › Revert are not this list's.
let mut footed = None;
let out = Stack::new()
.label(tl!("Swatches"))
@@ -428,7 +428,9 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui) {
let dragged_doc = Arc::clone(&doc);
let thumbs = Thumbs { revision, lit: lit.clone(), doc: Arc::clone(&doc) };
let browser = SwatchesPanel::new(&data, Bind::bound(&mut *state), Srgba::rgb(0.0, 0.0, 0.0))
.drag_payload(move |drag: &ListDrag<SwatchKey>| Some(dnd::drag_of(&dragged_doc, document, &drag.grabbed, dragged_rows(drag))))
.drag_payload(move |drag: &ListDrag<SwatchKey>| {
Some(dnd::drag_of(&dragged_doc, (document, reverts), &drag.grabbed, dragged_rows(drag)))
})
.thumb(thumbs, thumb)
.row_icons(|key| match key {
SwatchKey::Swatch(name) => row_icons(shown_app, name),
@@ -441,7 +443,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui) {
.search(search)
.reveal(focus.clone().map(SwatchKey::Swatch))
.footer(None);
ui.push_id(("swatch-rows", document), |ui| browser.show(ui)).inner
ui.push_id(("swatch-rows", document, reverts), |ui| browser.show(ui)).inner
})
.inner;
app.ui.swatches_panel = model;
@@ -790,7 +792,8 @@ struct Footer {
opts: Option<String>,
group: Option<String>,
libraries_open: bool,
document: Option<u64>,
/// The uid and revert count of the document the panel shows.
document: Option<(u64, u64)>,
}
impl Footer {
@@ -803,7 +806,7 @@ impl Footer {
Footer {
kind: model.kind,
libraries_open: library_panel::any_open::<SwatchLibraries>(&app.ui),
document: app.session.active().map(|state| state.uid),
document: app.session.active().map(|state| (state.uid, state.reverts)),
sel,
del,
opts,
@@ -815,7 +818,8 @@ impl Footer {
fn show(&self, ui: &mut Ui) -> FooterOutput {
let icon = |id: &'static str| IconSpec::svg(IconId::new(id));
let document = self.document;
let rows_drag = move |d: &PanelDrag| matches!(d, PanelDrag::Paint { rows: Some(rows), .. } if Some(rows.document) == document);
let rows_drag =
move |d: &PanelDrag| matches!(d, PanelDrag::Paint { rows: Some(rows), .. } if Some((rows.document, rows.reverts)) == document);
let edit = if self.group.is_some() {
FooterAction::new(icon("palette"), tl!("Edit or Apply Color Group"))
} else {
+5 -5
View File
@@ -4,10 +4,10 @@ use craft::color_ui::ui::SwatchKey;
use craft::keymap::Mods;
use craft::ui::contract::{DropAt, ReorderMove};
/// Swatches take paints, and take swatch rows or canvas art from the current document.
/// Swatches take paints, and take swatch rows or canvas art from the current document's current contents.
pub(super) fn accepts(drag: &PanelDrag, document: u64, reverts: u64) -> bool {
match drag {
PanelDrag::Paint { rows: Some(rows), .. } => rows.document == document,
PanelDrag::Paint { rows: Some(rows), .. } => (rows.document, rows.reverts) == (document, reverts),
PanelDrag::Paint { .. } => true,
_ => drag.artwork_for(document, reverts).is_some(),
}
@@ -52,7 +52,7 @@ impl Drop {
/// The drag a row of `key` starts, moving rows `names`. Colour groups have no paint of their own
/// (the chip under the pointer draws Registration's mark for Registration).
pub(super) fn drag_of(d: &Document, document: u64, key: &SwatchKey, names: Vec<String>) -> PanelDrag {
pub(super) fn drag_of(d: &Document, (document, reverts): (u64, u64), key: &SwatchKey, names: Vec<String>) -> PanelDrag {
let name = name_of(key);
let (paint, params, unlinked_process_color) = match key {
SwatchKey::Swatch(_) if name == REGISTRATION => (Paint::registration(), swatch_params(d, name), false),
@@ -65,7 +65,7 @@ pub(super) fn drag_of(d: &Document, document: u64, key: &SwatchKey, names: Vec<S
},
_ => (Paint::None, Value::Null, false),
};
let rows = SwatchRows { document, grabbed: name.to_string(), names, groups: matches!(key, SwatchKey::Group(_)), unlinked_process_color };
let rows = SwatchRows { document, reverts, grabbed: name.to_string(), names, groups: matches!(key, SwatchKey::Group(_)), unlinked_process_color };
PanelDrag::Paint { paint, params, rows: Some(rows), library: None }
}
@@ -126,7 +126,7 @@ pub(super) enum FooterTarget {
/// the button does. Other drags are left to their own targets.
pub(super) fn on_footer_drop(app: &mut VectorcraftApp, target: FooterTarget, drag: &PanelDrag) {
let PanelDrag::Paint { rows: Some(r), .. } = drag else { return };
if !app.session.active().is_some_and(|state| state.uid == r.document) {
if !app.session.active().is_some_and(|state| (state.uid, state.reverts) == (r.document, r.reverts)) {
return;
}
let rows = footer_rows(app, r);
+48 -1
View File
@@ -96,7 +96,7 @@ fn dropped_below(app: &mut VectorcraftApp, drag: PanelDrag, mods: Mods) {
/// The drag the row `name` starts, carrying rows `names`.
fn rows_drag(app: &VectorcraftApp, name: &str, names: &[&str]) -> PanelDrag {
let document = app.session.active().unwrap().uid;
let document = app.session.active().map(|st| (st.uid, st.reverts)).unwrap();
dnd::drag_of(&doc(app), document, &key_of(app, name), names.iter().map(|n| n.to_string()).collect())
}
@@ -157,6 +157,53 @@ fn a_swatch_row_drag_reorders_only_its_source_document() {
assert_eq!(names_of(&panel.app(), None), before_source);
}
/// Swatch rows held across File › Revert move nothing in the restored swatches, and drop nothing on New Swatch or
/// Delete Swatch; the same drag started after the revert still moves them.
#[test]
fn a_swatch_row_drag_held_across_file_revert_moves_nothing() {
use crate::tests::panel_harness::Panel;
use craft::ui::contract::Role;
use craft::ui::runtime::drag;
let mut app = app();
app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|e| e.to_string())));
app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|e| e.to_string())));
let folder = vectorcraft_testkit::TempDir::new("swatch-rows-revert");
let path = folder.join("drawing.vectorcraft");
app.run("file.saveAs", json!({"path": path.to_string_lossy()})).unwrap();
app.run("shape.ellipse", json!({"x": 20, "y": 20, "width": 20, "height": 20})).unwrap();
let stale = rows_drag(&app, "Red", &["Red"]);
let before = names_of(&app, None);
let mut panel = Panel::new(app, show);
let drag_red = |panel: &mut Panel| {
let red = "Red, #ed1c24";
let from = panel.rect(red).center();
let to = panel.rect("Green, #39b54a").center();
panel.drag_hold_role(red, Role::LIST_ITEM, to - from);
};
drag_red(&mut panel);
assert!(drag::mark(panel.ctx()).is_some(), "the list takes rows of the current contents");
panel.app().run("file.revert", json!({"confirmed": true})).unwrap();
panel.frame();
assert!(drag::mark(panel.ctx()).is_none(), "the list refuses rows of the contents File › Revert replaced");
panel.release();
assert_eq!(names_of(&panel.app(), None), before, "the stale rows move nothing");
let restored = doc(&panel.app());
let undo = undo_steps(&panel.app());
for target in [dnd::FooterTarget::New, dnd::FooterTarget::Delete] {
dnd::on_footer_drop(&mut panel.app(), target, &stale);
assert_eq!(doc(&panel.app()), restored);
assert_eq!(undo_steps(&panel.app()), undo);
assert!(!dialog_open(&panel.app(), crate::dialogs::confirm::KIND));
}
drag_red(&mut panel);
panel.release();
assert_ne!(names_of(&panel.app(), None), before, "a drag started after the revert still moves the rows");
}
#[test]
fn a_foreign_swatch_row_payload_cannot_move_or_replace_local_swatches() {
let mut app = app();
+14 -6
View File
@@ -58,6 +58,8 @@ fn thumb_px(size: f32, pixels_per_point: f32) -> u32 {
pub(crate) struct SymbolKey {
/// The uid of the document whose Symbols panel showed the symbol.
pub doc: u64,
/// The document's revert count: a drag held across File › Revert names a symbol of contents that are gone.
pub reverts: u64,
/// The symbol's name.
pub name: String,
}
@@ -496,6 +498,7 @@ pub(crate) fn control_bar(app: &mut VectorcraftApp, ui: &mut Ui) -> bool {
#[derive(MemoProps)]
struct SymbolSource<'a> {
uid: u64,
reverts: u64,
revision: u64,
#[memo_props(covered_by = "revision", reason = "a document version's symbols are fixed")]
doc: &'a Document,
@@ -506,7 +509,11 @@ struct SymbolSource<'a> {
/// The panel's presets: a row per symbol of the document, in its order, each with its thumbnail.
fn symbol_source(inputs: SymbolSource<'_>) -> PresetSource<'_, SymbolKey> {
let fns = PresetFns::<SymbolSource<'_>, SymbolKey>::new(|s, _| {
s.doc.symbols.iter().map(|sym| PresetRow::item(SymbolKey { doc: s.uid, name: sym.name.clone() }, sym.name.clone(), 0)).collect()
s.doc
.symbols
.iter()
.map(|sym| PresetRow::item(SymbolKey { doc: s.uid, reverts: s.reverts, name: sym.name.clone() }, sym.name.clone(), 0))
.collect()
})
.thumb(|s, cx, rect, info| paint_symbol(cx, rect, s.doc, s.keys, &info.key.name));
PresetSource::new(inputs, fns)
@@ -540,8 +547,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let marked = marked(app);
let inst = has_instances_selected(app);
let linked = linked_symbols(app);
let key = |name: &str| SymbolKey { doc: uid, name: name.to_string() };
let source = symbol_source(SymbolSource { uid, revision, doc: &doc, keys: &keys });
let key = |name: &str| SymbolKey { doc: uid, reverts, name: name.to_string() };
let source = symbol_source(SymbolSource { uid, reverts, revision, doc: &doc, keys: &keys });
// The symbols drawn selected: the ones Select All Unused picked, which further picks change,
// else the current one.
let (mut selection, select) = if marked.is_empty() {
@@ -552,8 +559,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let (view, zoom) = app.ui.symbols_view.preset();
let browser_id = ui.make_persistent_id("symbols-browser");
let list = PresetBrowser::<SymbolKey>::list_id(browser_id);
// A symbol dragged from this panel's list, of the document it shows.
let ours = move |drag: &ListDrag<SymbolKey>| drag.list == list && drag.grabbed.doc == uid;
// A symbol dragged from this panel's list, of the contents of the document it shows.
let ours = move |drag: &ListDrag<SymbolKey>| drag.list == list && (drag.grabbed.doc, drag.grabbed.reverts) == (uid, reverts);
let svg = |name: &'static str| IconSpec::svg(IconId::new(name));
let actions = [
FooterAction::new(svg("library"), tl!(SymbolLibraries::MENU))
@@ -656,7 +663,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let Some(out) = footer else { return };
match &out.dropped {
Some(dropped) => {
let Some(drag) = dropped.payload::<ListDrag<SymbolKey>>() else { return };
// A symbol of other contents, another document's or the ones File › Revert replaced, drops nothing.
let Some(drag) = dropped.payload::<ListDrag<SymbolKey>>().filter(|drag| ours(drag)) else { return };
let name = &drag.grabbed.name;
// A symbol deleted while it was dragged drops nothing.
if !doc.symbols.iter().any(|s| s.name == *name) {
+2 -1
View File
@@ -5807,7 +5807,8 @@ Their OK runs `brush.new {type, name, params, ids?}`, and Cancel adds no brush.
`brush.placeArt {name, x?, y?}` places a copy of the art a scatter, art or pattern brush is made of, centered on
(`x`, `y`) (default: the center of the first artboard), and selects it, in one undo step. The app runs it when a
brush is dragged from the Brushes panel onto an empty part of the canvas; dropped on a path, a brush is applied to it
(`brush.apply`). A pattern brush places its tiles left to right, 10 pt apart, in the order side, outer corner, inner
(`brush.apply`). A brush, graphic style, symbol, swatch or appearance whose drag started before File › Revert is not
dropped on the restored drawing. A pattern brush places its tiles left to right, 10 pt apart, in the order side, outer corner, inner
corner, start, end (only the tiles it has art for), each in a group named Side Tile, Outer Corner Tile, Inner Corner
Tile, Start Tile or End Tile. A tile with a repeat frame has an unpainted rectangle at the back of its group that marks
the frame. A symbol instance in the art is measured by its symbol's art. A calligraphic or bristle brush is refused