Non-Selecting Token Field

I posted some source code (NonSelectingTokenField) in response to a StackOverflow question. It avoids the default behavior of selecting all tokens when becoming first responder or ending editing.

The source code is a drop-in NSTokenField subclass, but it’s also a good example of how to change the selected range of any NSTextField subclass. Since there’s no direct method to manipulate the selected range in an NSTextField subclass – other than the brain-dead -selectText: method, which selects all text in the field – this question has come up countless times over the years.