Skip to content

Commit

Permalink
features/rearrange-columns: fix drop edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Sören Kuklau committed Apr 6, 2024
1 parent a52a6c0 commit 35729b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ class ArrangeColumnsWindowController: NSWindowController, NSCollectionViewDelega
}

func collectionView(_ collectionView: NSCollectionView, validateDrop draggingInfo: NSDraggingInfo, proposedIndexPath proposedDropIndexPath: AutoreleasingUnsafeMutablePointer<NSIndexPath>, dropOperation proposedDropOperation: UnsafeMutablePointer<NSCollectionView.DropOperation>) -> NSDragOperation {
if proposedDropOperation.pointee == .on {
proposedDropOperation.pointee = .before
}
print("proposed index path: \(proposedDropIndexPath.pointee.item), drop operation: \(proposedDropOperation.pointee)")

return .move
}

func collectionView(_ collectionView: NSCollectionView, acceptDrop draggingInfo: NSDraggingInfo, indexPath: IndexPath, dropOperation: NSCollectionView.DropOperation) -> Bool {
print("dropping at: \(indexPath.item)")

guard let stringResult = draggingInfo.draggingPasteboard.propertyList(forType: .string) as? String,
let stringUtf8Data = stringResult.data(using: .utf8)
else { return false }
Expand Down
14 changes: 12 additions & 2 deletions Mastonaut/Window Controllers/TimelinesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1145,10 +1145,20 @@ extension TimelinesWindowController // IBActions

wc.getColumnViewControllers = { [self] in timelinesViewController.columnViewControllers }
wc.moveColumnViewController = { [self]
newControllerAtOldIndex, newIndex in
newControllerAtOldIndex, _newIndex in

// if user drags past the end, treat it as the end
let newIndex = min(_newIndex, timelinesViewController.columnViewControllers.count - 1)

guard let oldIndex = timelinesViewController.columnViewControllers.firstIndex(where: { $0 == newControllerAtOldIndex }),
let newModeAtOldIndex = newControllerAtOldIndex.modelRepresentation,
oldIndex != newIndex
else {
print("oldIndex wasn't found or is the same as newIndex")

return
}

guard let newModeAtOldIndex = newControllerAtOldIndex.modelRepresentation,
let oldModeAtNewIndex = timelinesViewController.columnViewControllers[newIndex].modelRepresentation
else { return }

Expand Down

0 comments on commit 35729b6

Please sign in to comment.