Fixed lots of bugs in the text editor that occured after an auto-save.