restore cursor if the cursor is at the end