Skip to content

Commit 2096909

Browse files
committed
Update OutlineViewDiffableDataSource.swift
1 parent f2e91f7 commit 2096909

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/AdvancedCollectionTableView/DiffableDataSource/NSOutlineView/OutlineViewDiffableDataSource.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,15 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
547547

548548
public func outlineView(_ outlineView: NSOutlineView, acceptDrop info: any NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool {
549549
var snapshot = currentSnapshot
550-
snapshot.move(draggedItems, toIndex: index == -1 ? 0 : index, of: item as? ItemIdentifierType)
550+
var index = index
551+
if index == -1 {
552+
if let item = item as? ItemIdentifierType {
553+
index = snapshot.children(of: item).count
554+
} else {
555+
index = snapshot.rootItems.count
556+
}
557+
}
558+
snapshot.move(draggedItems, toIndex: index, of: item as? ItemIdentifierType)
551559
let transaction = OutlineViewDiffableDataSourceTransaction(initial: currentSnapshot, final: snapshot)
552560
reorderingHandlers.willReorder?(transaction)
553561
apply(snapshot, .usingReloadData)

0 commit comments

Comments
 (0)