Fix wrong cursor position in a certain case