Copied some TextInput grab/selection handle code