This should be a Bug, because I can reproduce it with my friends.
I just set allowsNonContiguous Layout of NSTextView. layoutManager to true, and that's the problem.
In the editor, I first enter N blank lines, that is, press N times to return. Then go back to the second line of our input, and press any key at the moment insertion Point disappears, which will make my insertion Point incorrect.
Here is my demo: https://github.com/iiiDD/TextViewDemo