sets the caret position correctly