Improve logic for automatic selection names
If a selection is directly provided from an external index group, the
name of the selection is set to be the name of the group, irrespective
of the exact way the group is selected. The code that did this was a
bit too eager, and used the name of the group that appeared around the
beginning of a more complex selection in some other cases, leading to
confusion.
Make the code only use the name of the group if the group is really used
as-is, and otherwise use the selection text. Add explicit tests for
this behavior.
Change-Id: Ic7fe2626a07cfd3cac3773046ed9f83484ba4368