DXF Import: a restored Objects on Path member keeps the paints

A restored selection loads its paints for new art only when the journal
records it with a selection command that loads them on replay. An
Objects on Path member, recorded as object.objectsOnPath.selectMember,
now keeps the paints as they are, as a symbol part already does.
This commit is contained in:
dotCooCoo committed 2026-12-05 17:46:16 -08:00
1 parent 374176f3c6
commit 14f92a1fa1
2 files changed
+35 -5

No files matched your search

+8 -5
View File
@@ -269,8 +269,9 @@ impl Session {
/// artboard that is not new art are left out. In the active document, outside a command and an
/// interaction, the journal records the selection that comes back, with the current layer kept,
/// in the open undo groups too, and the paints for new art load from it as `select.set` loads
/// them (with New Art Has Basic Appearance on, a symbol part does not load its paints, as
/// `symbol.instance.selectPart` does not), so a recorded action replays as it ran.
/// them (with New Art Has Basic Appearance on, a symbol part or an Objects on Path member does
/// not load its paints, as `symbol.instance.selectPart` and
/// `object.objectsOnPath.selectMember` do not), so a recorded action replays as it ran.
pub fn restore_selection(&mut self, uid: u64, selection: Selection) -> Result<()> {
let active = self.active().is_some_and(|st| st.uid == uid && st.interaction.is_none()) && self.depth == 0;
let st = self.document_mut(uid).ok_or(EngineError::NoDocument)?;
@@ -286,8 +287,10 @@ impl Session {
return Ok(());
}
let steps = selection_steps(&st.selection, &made, &st.doc, layer, &st.highlighted_rows());
// A symbol part comes back through `symbol.instance.selectPart`, which loads no paints.
let part = st.selection.symbol_part.is_some();
// Only the selection commands load paints on replay: a symbol part comes back through
// `symbol.instance.selectPart` and an Objects on Path member through
// `object.objectsOnPath.selectMember`, which load none.
let loads = steps.iter().any(|(id, _)| id.starts_with("select.") || id == "layer.target");
let (from, grouped) = (self.journal.len(), self.undo_group_docs());
for step in steps {
self.journal.push(step);
@@ -297,7 +300,7 @@ impl Session {
// of a defaults-only paint that ran before it.
self.defaults_only_ran = None;
self.inherit_new_art();
if !part {
if loads {
self.load_selection_paints();
}
Ok(())
@@ -875,3 +875,30 @@ fn objects_moved_out_together_in_the_layers_panel_all_leave_the_path() {
let (layer, at) = place_of(&s, g);
assert_eq!((place_of(&s, left), place_of(&s, middle)), ((layer, at + 1), (layer, at + 2)), "above the group, in their order");
}
/// A restored Objects on Path member keeps the paints for new art as they are, as the journal
/// entry that records it (`object.objectsOnPath.selectMember`) does when it is replayed.
#[test]
fn a_restored_member_leaves_the_same_paints_live_and_on_replay() {
let mut s = session();
let (g, [a, b, c], _) = three_on_a_line(&mut s);
s.execute("paint.setFill", &json!({"ids": [a.0, b.0, c.0, g.0], "color": "#ff0000"})).unwrap();
s.execute("object.objectsOnPath.selectMember", &json!({"member": b.0})).unwrap();
let saved = s.doc().unwrap().selection.clone();
let blue = rect(&mut s, 400.0, 0.0, 10.0, 10.0);
s.execute("paint.setFill", &json!({"ids": [blue.0], "color": "#0000ff"})).unwrap();
select(&mut s, &[blue]);
let before = s.paint.clone();
let (uid, from) = (s.doc().unwrap().uid, s.journal.len());
s.restore_selection(uid, saved.clone()).unwrap();
assert_eq!(s.doc().unwrap().selection, saved);
assert_eq!(s.paint, before, "selecting a member keeps the paints for new art");
let steps = s.journal.since(from).to_vec();
assert_eq!(steps.iter().map(|(c, _)| c.as_str()).collect::<Vec<_>>(), ["object.objectsOnPath.selectMember"]);
select(&mut s, &[blue]);
for (cmd, p) in steps {
s.execute(&cmd, &p).unwrap();
}
assert_eq!(s.doc().unwrap().selection, saved);
assert_eq!(s.paint, before, "the replay leaves the same paints");
}