Fix cursor positioning on text insertion