NSBackgroundColorAttributeName in textView doesn't respect range if highlighted word is first of a line
Seems like a bug in the system framework, so probably best bet would be to add one more line of code, setting background color back to "unchanged", directly after the last character where background should be changed. Good luck!