diff --git a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift index d81048636..935b97458 100644 --- a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift +++ b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift @@ -262,10 +262,22 @@ private extension SidebarOutlineDataSource { return accounts } + func accountHasFolderRepresentingAnyDraggedFolders(_ account: Account, _ draggedFolders: Set) -> Bool { + for draggedFolder in draggedFolders { + if account.existingFolder(with: draggedFolder.name) != nil { + return true + } + } + return false + } + func validateLocalFolderDrop(_ outlineView: NSOutlineView, _ draggedFolder: PasteboardFolder, _ parentNode: Node, _ index: Int) -> NSDragOperation { guard let dropAccount = parentNode.representedObject as? Account, dropAccount.accountID != draggedFolder.accountID else { return SidebarOutlineDataSource.dragOperationNone } + if accountHasFolderRepresentingAnyDraggedFolders(dropAccount, Set([draggedFolder])) { + return SidebarOutlineDataSource.dragOperationNone + } let updatedIndex = indexWhereDraggedFolderWouldAppear(parentNode, draggedFolder) if index != updatedIndex { outlineView.setDropItem(parentNode, dropChildIndex: updatedIndex) @@ -277,6 +289,9 @@ private extension SidebarOutlineDataSource { guard let dropAccount = parentNode.representedObject as? Account else { return SidebarOutlineDataSource.dragOperationNone } + if accountHasFolderRepresentingAnyDraggedFolders(dropAccount, draggedFolders) { + return SidebarOutlineDataSource.dragOperationNone + } for draggedFolder in draggedFolders { if dropAccount.accountID == draggedFolder.accountID { return SidebarOutlineDataSource.dragOperationNone