Selecting and typing text.

When selecting and typing text, the range was wrong, so the text was inserted in the wrong position.