Avoid crash in history service

The LogActiveDocument call may alter the history, so the CanMoveBack
or Forward checks may change after that call, so they have to be checked
again before calling MoveBack/Forward.

Fixes bug #24282 - Navigate Forward/Backward throws an exception