Fix cursor positioning after insertion of text