Improved saving caret position