This still doesn't quite match what Android does, but I'll bring that up as a different issue and solve it independently of this specific improvement.