Avoid range selection on empty groups

This prevents a traceback when the group is empty.
Fixes #6258