Improve undo manager state handling.
Fix double push to the undo stack when redoing.