From c0a8067c817774455f765eba598116765f84a6d5 Mon Sep 17 00:00:00 2001 From: Juan Manuel Pereira Date: Mon, 2 Sep 2024 14:30:59 -0300 Subject: [PATCH] Fix bug when reordering on bookmark search --- DuckDuckGo/Bookmarks/Model/BookmarkDragDropManager.swift | 8 ++++++++ .../Bookmarks/Model/BookmarkOutlineViewDataSource.swift | 7 +++++++ .../Bookmarks/View/BookmarkListViewController.swift | 2 +- .../View/BookmarkManagementDetailViewController.swift | 8 +++++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/DuckDuckGo/Bookmarks/Model/BookmarkDragDropManager.swift b/DuckDuckGo/Bookmarks/Model/BookmarkDragDropManager.swift index 9eaabcc4f0..324a1ddba3 100644 --- a/DuckDuckGo/Bookmarks/Model/BookmarkDragDropManager.swift +++ b/DuckDuckGo/Bookmarks/Model/BookmarkDragDropManager.swift @@ -54,6 +54,14 @@ final class BookmarkDragDropManager { } } + func validateDropWhileInSearchMode(_ info: NSDraggingInfo, to destination: Any) -> (destinationFolder: BookmarkFolder?, operation: NSDragOperation) { + if let destinationFolder = destination as? BookmarkFolder { + return (destinationFolder, .move) + } + + return (nil, .none) + } + private func validateMove(for draggedBookmarks: Set, destination: Any) -> Bool? { guard !draggedBookmarks.isEmpty else { return nil } guard destination is BookmarkFolder || destination is PseudoFolder else { return false } diff --git a/DuckDuckGo/Bookmarks/Model/BookmarkOutlineViewDataSource.swift b/DuckDuckGo/Bookmarks/Model/BookmarkOutlineViewDataSource.swift index c80c02f163..69a3520d7d 100644 --- a/DuckDuckGo/Bookmarks/Model/BookmarkOutlineViewDataSource.swift +++ b/DuckDuckGo/Bookmarks/Model/BookmarkOutlineViewDataSource.swift @@ -264,6 +264,13 @@ final class BookmarkOutlineViewDataSource: NSObject, BookmarksOutlineViewDataSou } let destination = destinationNode.isRoot ? PseudoFolder.bookmarks : destinationNode.representedObject + + if isSearching { + let result = dragDropManager.validateDropWhileInSearchMode(info, to: destination) + self.dragDestinationFolder = result.destinationFolder + return result.operation + } + let operation = dragDropManager.validateDrop(info, to: destination) self.dragDestinationFolder = (operation == .none || item == nil) ? nil : destinationNode.representedObject as? BookmarkFolder diff --git a/DuckDuckGo/Bookmarks/View/BookmarkListViewController.swift b/DuckDuckGo/Bookmarks/View/BookmarkListViewController.swift index 234404402c..4b4bd45bef 100644 --- a/DuckDuckGo/Bookmarks/View/BookmarkListViewController.swift +++ b/DuckDuckGo/Bookmarks/View/BookmarkListViewController.swift @@ -451,7 +451,7 @@ final class BookmarkListViewController: NSViewController { expandFoldersAndScrollUntil(folder) outlineView.scrollToAdjustedPositionInOutlineView(folder) - guard let node = treeController.node(representing: folder) else { return } + guard let node = treeController.findNodeWithId(representing: folder) else { return } outlineView.highlight(node) } diff --git a/DuckDuckGo/Bookmarks/View/BookmarkManagementDetailViewController.swift b/DuckDuckGo/Bookmarks/View/BookmarkManagementDetailViewController.swift index f857da6728..73903b343d 100644 --- a/DuckDuckGo/Bookmarks/View/BookmarkManagementDetailViewController.swift +++ b/DuckDuckGo/Bookmarks/View/BookmarkManagementDetailViewController.swift @@ -473,7 +473,13 @@ extension BookmarkManagementDetailViewController: NSTableViewDelegate, NSTableVi proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation { let destination = destination(for: dropOperation, at: row) - return dragDropManager.validateDrop(info, to: destination) + + if isSearching { + let result = dragDropManager.validateDropWhileInSearchMode(info, to: destination) + return result.operation + } else { + return dragDropManager.validateDrop(info, to: destination) + } } func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableView.DropOperation) -> Bool {