fix caret position when adding character before mask characters