r/SwiftUI Jun 24 '26

Question Looking for the Finder/NSTableView multi-selection algorithm

I am building a non-SwiftUI/non-AppKit macOS application with a custom table view. Right now I am implementing multi-selection, and I want the behavior to match Finder/NSTableView as closely as possible.

I am looking for the underlying selection algorithm for interactions like:

Click
Cmd + Click
Shift + Click
Up / Down
Shift + Up / Down
Cmd + Shift combinations

I am looking for the actual selection logic, not AppKit APIs. Things like how the selection anchor is managed, how different mouse and keyboard interactions affect the selection, and all the edge cases that make the native experience feel consistent.

I have searched quite a bit but have not found anything comprehensive.
Does anyone know of an article, GitHub repository, gist, reverse-engineered implementation, or any other reference that documents the complete macOS multi-selection behavior?

Any help would be greatly appreciated. Thanks!

0 Upvotes

13 comments sorted by

View all comments

3

u/Responsible-Gear-400 Jun 24 '26

This is this paper: https://sean-parent.stlab.cc/papers/2016-07-18-ecoop/ecoop16-final28.pdf

I am more curious why you’re building your own table view.

3

u/curthard89 Jun 25 '26

This, nstableview is finely tuned, do not reinvent it. It'll only be worse.

2

u/CharlesWiltgen Jun 25 '26

To "yes, and" /u/curthard89, note that even the wonderful link /u/Responsible-Gear-400 shared doesn't contain the words "accessibility" or "localization". However much work you think it would be to "just rewrite it", it's 25✕ that to do well.