Skip to content

Commit

Permalink
fix: Updating selection and contents at the same time can leads to ha…
Browse files Browse the repository at this point in the history
…ngs (#17)

I've noticed that it's possible to cause a hang when updating the
contents and selection at the same time. This works around that by
asynchronously dispatching the selection set back to the main queue to
break the (assumed) dependency loop.
  • Loading branch information
jbmorley authored Mar 26, 2024
1 parent 9ef34bb commit 9a0a461
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ public class CollectionViewContainer<Element: Hashable, Content: View>: NSView,
let indexPaths = selection.compactMap { element in
return dataSource?.indexPath(for: element)
}
collectionView.selectionIndexPaths = Set(indexPaths)

// Updating the selection at the same time as the items seems to cause some form of loop or deadlock, so we
// break that by dispatching back to the main queue.
DispatchQueue.main.async {
self.collectionView.selectionIndexPaths = Set(indexPaths)
}

}

Expand Down

0 comments on commit 9a0a461

Please sign in to comment.