Why the Selection Changes When You Do Syntax Highlighting in a NSTextView
In short: when you type and the attributes of the line change, the insertion point is moved to the end of the line. That sucks.
TL;DR: Do not perform style changes inside of
NSTextStorage.processEditing()
orNSTextStorageDelegate
methods but subscribe toNSText.didChangeNotification
orNSTextDelegate
orNSTextViewDelegate.textDidChange(_:)
.