fix a bug with error position of cursor