fix item preselection in goto popups

This commit is contained in:
peter
2016-08-25 15:11:17 +02:00
parent 707eedbeed
commit 196bd1b867
2 changed files with 13 additions and 2 deletions
@@ -329,6 +329,16 @@ class Intf {
assert popup.calcSelectedIndex(popupElements.toArray(), 'xfile') == 0
}
public void "test prefer prefix match"() {
def wanted = myFixture.addClass('class PsiClassImpl {}')
def smth = myFixture.addClass('class DroolsPsiClassImpl {}')
def popup = createPopup(new GotoClassModel2(project))
def popupElements = calcPopupElements(popup, 'PsiCl', false)
assert popupElements == [wanted, ChooseByNameBase.NON_PREFIX_SEPARATOR, smth]
assert popup.calcSelectedIndex(popupElements.toArray(), 'PsiCl') == 0
}
private List<Object> getPopupElements(ChooseByNameModel model, String text, boolean checkboxState = false) {
return calcPopupElements(createPopup(model), text, checkboxState)
}
@@ -1082,9 +1082,10 @@ public abstract class ChooseByNameBase {
Matcher matcher = buildPatternMatcher(transformPattern(trimmedText));
final String statContext = statisticsContext();
Comparator<Object> itemComparator = Comparator.
comparing(e -> !trimmedText.equalsIgnoreCase(myModel.getElementName(e))).
comparing(e -> trimmedText.equalsIgnoreCase(myModel.getElementName(e))).
thenComparing(e -> matchingDegree(matcher, e)).
thenComparing(e -> getUseCount(statContext, e));
thenComparing(e -> getUseCount(statContext, e)).
reversed();
int bestPosition = 0;
for (int i = 1; i < modelElements.length; i++) {