The code is now clearer, and will prefer the nearer end of the atomic range as long as that means there is still progress (i.e. the cursor does not get stuck). Issue #3658