Text selection refactoring