Skip to content

Commit

Permalink
Fix bug when reordering on bookmark search
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaemepereira committed Sep 2, 2024
1 parent 3b52dd7 commit c0a8067
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions DuckDuckGo/Bookmarks/Model/BookmarkDragDropManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<PasteboardBookmark>, destination: Any) -> Bool? {
guard !draggedBookmarks.isEmpty else { return nil }
guard destination is BookmarkFolder || destination is PseudoFolder else { return false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Bookmarks/View/BookmarkListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c0a8067

Please sign in to comment.