in Go To Class preselect the item with the biggest matching degree (IDEA-69335)

This commit is contained in:
peter
2011-05-12 18:15:29 +02:00
parent 3076b045e8
commit cc70c30883
@@ -87,6 +87,7 @@ public abstract class ChooseByNameBase {
private boolean myPreselectInitialText;
private final Reference<PsiElement> myContext;
private boolean mySearchInAnyPlace = false;
private NameUtil.Matcher myLastMatcher;
protected Component myPreviouslyFocusedComponent;
@@ -873,17 +874,23 @@ public abstract class ChooseByNameBase {
private int detectBestStatisticalPosition() {
int best = 0;
int bestPosition = 0;
int bestMatch = Integer.MIN_VALUE;
final int count = myListModel.getSize();
NameUtil.Matcher matcher = buildPatternMatcher(getNamePattern(myTextField.getText()));
final String statContext = statisticsContext();
for (int i = 0; i < count; i++) {
final Object modelElement = myListModel.getElementAt(i);
String text = EXTRA_ELEM.equals(modelElement) ? null : myModel.getFullName(modelElement);
if (text != null) {
String shortName = myModel.getElementName(modelElement);
int match = shortName != null && matcher instanceof NameUtil.MinusculeMatcher ? ((NameUtil.MinusculeMatcher)matcher).matchingDegree(shortName) : Integer.MIN_VALUE;
int stats = StatisticsManager.getInstance().getUseCount(new StatisticsInfo(statContext, text));
if (stats > best) {
if (stats > best || stats == best && match > bestMatch) {
best = stats;
bestPosition = i;
bestMatch = match;
}
}
}