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] =?UTF-8?q?Track=20the=20active=20object=E2=80=99s=20landi?= =?UTF-8?q?ng=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