Fix a bug where the cursor position was invalidated after a character insetion