From 1f159a5bff2dce789a88378bf3765eca45d4b261 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Mon, 22 Feb 2021 18:50:29 -0600 Subject: [PATCH] Change drag-n-drop behavior to default to copy when dragging between accounts --- .../Sidebar/SidebarOutlineDataSource.swift | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift index 384b7ba49..052f9bfca 100644 --- a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift +++ b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift @@ -215,13 +215,13 @@ private extension SidebarOutlineDataSource { return SidebarOutlineDataSource.dragOperationNone } if parentNode == dropTargetNode && index == NSOutlineViewDropOnItemIndex { - return localDragOperation() + return localDragOperation(parentNode: parentNode) } let updatedIndex = indexWhereDraggedFeedWouldAppear(dropTargetNode, draggedFeed) if parentNode !== dropTargetNode || index != updatedIndex { outlineView.setDropItem(dropTargetNode, dropChildIndex: updatedIndex) } - return localDragOperation() + return localDragOperation(parentNode: parentNode) } func validateLocalFeedsDrop(_ outlineView: NSOutlineView, _ draggedFeeds: Set, _ parentNode: Node, _ index: Int) -> NSDragOperation { @@ -238,14 +238,23 @@ private extension SidebarOutlineDataSource { if parentNode !== dropTargetNode || index != NSOutlineViewDropOnItemIndex { outlineView.setDropItem(dropTargetNode, dropChildIndex: NSOutlineViewDropOnItemIndex) } - return localDragOperation() + return localDragOperation(parentNode: parentNode) } - func localDragOperation() -> NSDragOperation { - if NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false { - return .copy + func localDragOperation(parentNode: Node) -> NSDragOperation { + guard let firstDraggedNode = draggedNodes?.first else { return .move } + if sameAccount(firstDraggedNode, parentNode) { + if NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false { + return .copy + } else { + return .move + } } else { - return .move + if NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false { + return .move + } else { + return .copy + } } } @@ -294,7 +303,7 @@ private extension SidebarOutlineDataSource { if index != updatedIndex { outlineView.setDropItem(parentNode, dropChildIndex: updatedIndex) } - return localDragOperation() + return localDragOperation(parentNode: parentNode) } func validateLocalFoldersDrop(_ outlineView: NSOutlineView, _ draggedFolders: Set, _ parentNode: Node, _ index: Int) -> NSDragOperation { @@ -312,7 +321,7 @@ private extension SidebarOutlineDataSource { if index != NSOutlineViewDropOnItemIndex { outlineView.setDropItem(parentNode, dropChildIndex: NSOutlineViewDropOnItemIndex) } - return localDragOperation() + return localDragOperation(parentNode: parentNode) } func copyWebFeedInAccount(node: Node, to parentNode: Node) { @@ -445,9 +454,9 @@ private extension SidebarOutlineDataSource { } } else { if NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false { - copyWebFeedBetweenAccounts(node: node, to: parentNode) - } else { moveWebFeedBetweenAccounts(node: node, to: parentNode) + } else { + copyWebFeedBetweenAccounts(node: node, to: parentNode) } } } @@ -571,9 +580,9 @@ private extension SidebarOutlineDataSource { draggedNodes.forEach { node in if !sameAccount(node, parentNode) { if NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false { - copyFolderBetweenAccounts(node: node, to: parentNode) - } else { moveFolderBetweenAccounts(node: node, to: parentNode) + } else { + copyFolderBetweenAccounts(node: node, to: parentNode) } } }