as convention, if a text range is (x, -1), it means from x to the end, so if `to` was -1, set it to the last position
Solve textctrl handle char type event twice error, correct the insertion point calculation