From e4b25a66a0f8a68177727ba2ef307aaebc377dfb Mon Sep 17 00:00:00 2001 From: clawdbot Date: Thu, 29 Jan 2026 05:38:10 +0800 Subject: [PATCH] editor: fix context menu zIndex enable states --- packages/editor/src/editor/ContextMenu.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/editor/ContextMenu.tsx b/packages/editor/src/editor/ContextMenu.tsx index 7df54ff..792464b 100644 --- a/packages/editor/src/editor/ContextMenu.tsx +++ b/packages/editor/src/editor/ContextMenu.tsx @@ -136,7 +136,16 @@ export function ContextMenu(props: { const movableSelectionIds = selectedNodes.filter((n) => !n.locked).map((n) => n.id); const movableSet = new Set(movableSelectionIds); - const orderIds = props.nodes.map((n) => n.id); + + // IMPORTANT: node order must reflect zIndex (back→front) rather than raw array order, + // otherwise enable/disable state for zIndex actions can get out of sync. + const orderIds = props.nodes + .map((n, index) => ({ n, index, z: n.zIndex ?? index })) + .sort((a, b) => { + if (a.z !== b.z) return a.z - b.z; + return a.index - b.index; + }) + .map((e) => e.n.id); const maxMovableIndex = movableSelectionIds.length ? Math.max(...movableSelectionIds.map((id) => orderIds.indexOf(id)).filter((i) => i >= 0))