Update the caret position on click and focus