From c8546789635e79f96862af260b97d688345910e6 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 19:54:54 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Track=20the=20active=20object=E2=80=99s=20l?= =?UTF-8?q?anding=20when=20moving=20one=20appearance=20row?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/engine/src/cmd/appearance.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 037983da5c..81c11f026e 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -1681,6 +1681,8 @@ fn move_item(s: &mut Session, p: &Value) -> Result { let from = index_param(p, "from", C)?; let contents = p.get("contents").map(|_| index_param(p, "contents", C)).transpose()?; let mut landed = to; + let active = s.active_appearance_item.as_ref().and_then(|a| a.objects.first().copied()); + let mut active_landed = None; // When every object's stack comes out as it was, the document and its undo history stay as they // are. let before = s.doc()?.doc.clone(); @@ -1688,6 +1690,9 @@ fn move_item(s: &mut Session, p: &Value) -> Result { for id in &ids { let Some(n) = d.node_mut(*id) else { continue }; landed = n.appearance.move_item(from, to).ok_or_else(|| bad(C, format!("no item at index {from}")))?; + if active == Some(*id) { + active_landed = Some(landed); + } if let Some(k) = contents.filter(|_| n.contents_label().is_some()) { n.appearance.set_contents_at(k); } @@ -1697,13 +1702,14 @@ fn move_item(s: &mut Session, p: &Value) -> Result { let labels = super::graph::capture_label_changes(&before, d, &ids, true, None); Ok(count_changed(d, &before, &ids) + usize::from(kept || painted || labels)) })?; - // The moved row stays the active one; the rows it passed shift by one. + // Track the row in its own object's stack, since other stacks may clamp to a different index. + let at = active_landed.unwrap_or(landed); s.remap_appearance_item(&ids, |a| { Some(if a == from { - landed - } else if from < a && a <= landed { + at + } else if from < a && a <= at { a - 1 - } else if landed <= a && a < from { + } else if at <= a && a < from { a + 1 } else { a From aa860cbcfe95e44cd3ce882dfe8868e4a7b6fb22 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 19:55:13 +0100 Subject: [PATCH 2/2] Cover active rows on stacks of different lengths --- crates/engine/src/tests/appearance.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/engine/src/tests/appearance.rs b/crates/engine/src/tests/appearance.rs index a04bb89b4a..13ab0e6bb5 100644 --- a/crates/engine/src/tests/appearance.rs +++ b/crates/engine/src/tests/appearance.rs @@ -145,6 +145,23 @@ fn item_rows_follow_remove_and_move() { assert_eq!(s.appearance_item(), None); } +#[test] +fn moving_a_single_row_keeps_the_active_objects_landing() { + let mut s = session(); + let short = rect(&mut s, 50.0); + let long = rect(&mut s, 200.0); + run(&mut s, "appearance.addFill", json!({})); + run(&mut s, "select.set", json!({"ids": [short.0, long.0]})); + run(&mut s, "appearance.setActiveItem", json!({"index": 0})); + + let moved = run(&mut s, "appearance.moveItem", json!({"ids": [short.0, long.0], "from": 0, "to": 2})); + + assert_eq!(moved["index"], 2, "the command still reports the last target's landing"); + assert!(matches!(node(&s, short).appearance.items[1], AppearanceItem::Fill(_))); + assert!(matches!(node(&s, long).appearance.items[0], AppearanceItem::Stroke(_))); + assert_eq!(s.appearance_item(), Some(1), "the active row follows its own object's landing"); +} + #[test] fn transparency_goes_to_the_targeted_item() { let mut s = session();