refactoring caret collapse