Made textBeforeCaret smarter