Extract autocomplete text cursor functions

and move them to the text API