Making a background document active can measure its type again and replace the document, so the undo step is now found by the document read after the switch. A test covers a background document whose text is measured again.