Solve bug in NSTextView cursor and add tests.