@@ -1019,13 +1019,13 @@ extension ConnectionOutlineView {
10191019 . filter { $0. parentGroupId == newParentId && $0. id != group. id }
10201020 . sorted { $0. sortOrder < $1. sortOrder }
10211021
1022- // Adjust childIndex: NSOutlineView counts both groups and connections
1023- let childConns = childrenMap [ newParentId ] ? . compactMap { $0 as? OutlineConnection } ?? [ ]
1024- let groupIndex = max ( 0 , childIndex - childConns . count)
1022+ // childIndex is in childrenMap order ( groups first, then connections).
1023+ // Clamp to sibling group count since we only reorder among groups.
1024+ let groupIndex = min ( childIndex , siblings . count)
10251025
10261026 var movedGroup = group
10271027 movedGroup. parentGroupId = newParentId
1028- siblings. insert ( movedGroup, at: min ( groupIndex, siblings . count ) )
1028+ siblings. insert ( movedGroup, at: groupIndex)
10291029
10301030 for (order, var g) in siblings. enumerated ( ) {
10311031 g. sortOrder = order
@@ -1052,13 +1052,13 @@ extension ConnectionOutlineView {
10521052 . filter { $0. parentGroupId == nil && $0. id != group. id }
10531053 . sorted { $0. sortOrder < $1. sortOrder }
10541054
1055- // Adjust childIndex: root items mix groups and connections
1056- let rootConnCount = rootItems . compactMap { $0 as? OutlineConnection } . count
1057- let groupIndex = max ( 0 , childIndex - rootConnCount )
1055+ // childIndex is in rootItems order ( groups first, then connections).
1056+ // Clamp to group count since we only reorder among groups.
1057+ let groupIndex = min ( childIndex , rootGroupSiblings . count )
10581058
10591059 var movedGroup = group
10601060 movedGroup. parentGroupId = nil
1061- rootGroupSiblings. insert ( movedGroup, at: min ( groupIndex, rootGroupSiblings . count ) )
1061+ rootGroupSiblings. insert ( movedGroup, at: groupIndex)
10621062
10631063 for (order, var g) in rootGroupSiblings. enumerated ( ) {
10641064 g. sortOrder = order
0 commit comments