Reset also selectionEnd and remove redundant resetting in couple of places.