LPS-46221 Improve caretIndex calculation after insertion