Fix undo issues with .arg/.cast/.for templates