Add replaceText method to the editor

Allows replacing text without messing up the cursor.