fix undo index going out of bounds in some cases

Undoindex went a little wonky in some cases

For instance, hitting control Z over and over would make it negative and then while trying to prune the revisions it would get in an infinite loop.  There also were some oddities when undoing all the way to the first entry and it wouldn't prune them.