Add functions to manage caret position