feat: Sort selected workspace items by Z-index to ensure consistent order.

This commit is contained in:
2025-11-28 01:13:53 +01:00
parent e512c8215e
commit 635747a1ee
+12 -3
View File
@@ -150,12 +150,21 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
} = useWorkspaceSelectionContext();
const handleSelectionChange = useCallback((ids: Identifier[]) => {
// Sort IDs by Z-index (ascending) so the last item is the top-most
const sortedIds = [...ids].sort((a, b) => {
const cardA = layoutStore.items.get(String(a));
const cardB = layoutStore.items.get(String(b));
const zA = cardA ? cardA.z : -Infinity;
const zB = cardB ? cardB.z : -Infinity;
return zA - zB;
});
if (setSelectedEntries) {
const keys = ids.map(id => createDocumentEntryKey(id));
const keys = sortedIds.map(id => createDocumentEntryKey(id));
setSelectedEntries(keys);
}
onSelectionChange?.(ids);
}, [setSelectedEntries, onSelectionChange]);
onSelectionChange?.(sortedIds);
}, [setSelectedEntries, onSelectionChange, layoutStore]);
const onClearSelection = useCallback(() => {
clearSelection ? clearSelection() : handleSelectionChange([]);