From cc70c3088334402d654337b7f2c19b127344b89e Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 12 May 2011 17:42:23 +0200 Subject: [PATCH] in Go To Class preselect the item with the biggest matching degree (IDEA-69335) --- .../intellij/ide/util/gotoByName/ChooseByNameBase.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java index 3d19a55f032e..3ce6cdddb663 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/ChooseByNameBase.java @@ -87,6 +87,7 @@ public abstract class ChooseByNameBase { private boolean myPreselectInitialText; private final Reference 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; } } }