Fix not returning correct position when selection does not end at text length.