Fix infinite loop when the match is not within the visible screen