Add UndoRedo for plain templates
Fix selection to file end