Libraries: a swatch row held across File › Revert is not added to a library

The Libraries panel accepted a swatch row dragged before File › Revert and added the restored swatch of that name. Membership::grabbed now refuses stale rows, for the hover marker and on release.
This commit is contained in:
dotCooCoo
2026-11-28 21:05:01 -08:00
parent 3381168a7e
commit 5f99cb7ebb
3 changed files with 47 additions and 1 deletions
+3
View File
@@ -205,6 +205,9 @@ impl Membership {
/// The item of this library that `drag` holds, or what it would add. `library.add` reads object IDs in the current document.
fn grabbed(&self, drag: &PanelDrag) -> Option<Grab> {
if drag.stale_rows(self.active_document) {
return None;
}
let library = &self.library;
match drag {
PanelDrag::Paint { library: Some((l, item)), .. } if l == library => Some(Grab::Item(ItemKind::Color, item.clone())),
@@ -277,6 +277,48 @@ fn a_library_drop_does_not_collect_unrelated_artwork_after_a_document_switch() {
assert_eq!(graphics(&mut panel.app()).len(), 1, "artwork from the current document can still be added");
}
#[test]
fn a_library_drop_of_a_swatch_row_held_across_file_revert_adds_nothing() {
use crate::panel_drag::SwatchRows;
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())));
app.run("library.create", json!({"name": "Brand"})).unwrap();
let name = "Sunset";
let gradient = json!({"stops": [{"offset": 0, "color": "#ffcc00"}, {"offset": 1, "color": "#cc3300"}]});
app.run("swatch.new", json!({"name": name, "gradient": gradient})).unwrap();
let folder = vectorcraft_testkit::TempDir::new("library-swatch-drop-revert");
let path = folder.join("drawing.vectorcraft");
app.run("file.saveAs", json!({"path": path.to_string_lossy()})).unwrap();
let gradient = json!({"stops": [{"offset": 0, "color": "#00ff00"}, {"offset": 1, "color": "#0000ff"}]});
app.run("swatch.edit", json!({"name": name, "paint": {"gradient": gradient}})).unwrap();
let state = app.session.active().unwrap();
let held = PanelDrag::Paint {
paint: state.doc.swatch(name).unwrap().paint.clone(),
params: json!({"swatch": name}),
rows: Some(SwatchRows {
document: state.uid,
reverts: state.reverts,
grabbed: name.into(),
names: vec![name.into()],
groups: false,
unlinked_process_color: false,
}),
library: None,
};
app.run("file.revert", json!({"confirmed": true})).unwrap();
let state = app.session.active().unwrap();
let membership = Membership::of("Brand", app.session.libraries.get("Brand").unwrap(), Some((state.uid, state.reverts)));
assert!(membership.landing(&held, None).is_none(), "hover refuses the stale swatch row");
let mut panel = Harness::new(app, with_source);
panel.frame();
let at = panel.rect("This library is empty").center();
drop_at(&mut panel, held, at);
assert!(panel.app().session.libraries.get("Brand").unwrap().gradients.is_empty(), "release adds no gradient");
}
#[test]
fn gradients_and_patterns_come_from_swatches_and_paint_the_selection() {
let mut app = app();
app.run("library.create", json!({"name": "Brand"})).unwrap();
+2 -1
View File
@@ -6956,7 +6956,8 @@ the panel shows) is meant.
takes them), `fillColor` / `strokeColor` (the first selected object's solid colour, else the default one, or `color`),
`charStyle` / `paraStyle` (the selected text's attributes). The new item goes into `group` (by default into none) and,
with `before` or `after` (another item of its kind), just before or after that item, as `library.moveItem` places one;
art and swatches dropped among the panel's items are added this way. An item the library already has is reported as
art and swatches dropped among the panel's items are added this way (a swatch dragged before File › Revert of its
drawing is not added). An item the library already has is reported as
`existing`, and stays where it is. `library.use {library?, kind, item,
center?, to?}` uses one: a graphic is placed centred on `center` (pasted with its resources; a swatch name the document
gives another colour merges into the document's), a colour paints the selection's fill or stroke, and a style is added