diff --git a/java/java-tests/testSrc/com/intellij/navigation/GotoActionTest.groovy b/java/java-tests/testSrc/com/intellij/navigation/GotoActionTest.groovy index 0919e3ff8821..0ea1a8277cd4 100644 --- a/java/java-tests/testSrc/com/intellij/navigation/GotoActionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/navigation/GotoActionTest.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,6 +43,20 @@ class GotoActionTest extends LightCodeInsightFixtureTestCase { matchedValue(byDesc, pattern, GotoActionModel.MatchMode.DESCRIPTION)].sort() assert [byName, byDesc] == items.collect { it.valueText } } + + public void "test sort by degree"() { + def pattern = 'c' + def copy = 'Copy' + def aardvark = 'Aardvarck' + def boom = 'Boom' + def deaf = 'deaf' + def eclaire = 'eclaire' + def cut = 'Cut' + def c = 'c' + def items = [matchedValue(boom, pattern), matchedValue(aardvark, pattern), matchedValue(copy, pattern), + matchedValue(eclaire, pattern), matchedValue(deaf, pattern), matchedValue(cut, pattern), matchedValue(c, pattern)].sort() + assert [c, copy, cut, aardvark, eclaire, boom, deaf] == items.collect { it.valueText } + } static def matchedValue(String fork, String pattern) { matchedValue(fork, pattern, GotoActionModel.MatchMode.NAME) diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java index c0580a4d33f0..e9a024695c74 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java @@ -191,6 +191,9 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel, C @Override public int compareTo(@NotNull MatchedValue o) { + int diff = o.getMatchingDegree() - getMatchingDegree(); + if (diff != 0) return diff; + boolean edt = ApplicationManager.getApplication().isDispatchThread(); if (value instanceof ActionWrapper && o.value instanceof ActionWrapper) { @@ -219,9 +222,6 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel, C if (value instanceof OptionDescription && !(o.value instanceof OptionDescription)) return 1; if (o.value instanceof OptionDescription && !(value instanceof OptionDescription)) return -1; - int diff = o.getMatchingDegree() - getMatchingDegree(); - if (diff != 0) return diff; - diff = StringUtil.notNullize(getValueText()).length() - StringUtil.notNullize(o.getValueText()).length(); if (diff != 0) return diff; @@ -622,10 +622,10 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel, C Presentation oPresentation = o.getAction().getTemplatePresentation(); String myText = myPresentation.getText(); String oText = oPresentation.getText(); + int byText = StringUtil.compare(StringUtil.trimEnd(myText, "..."), StringUtil.trimEnd(oText, "..."), true); + if (byText != 0) return byText; int byTextLength = StringUtil.notNullize(myText).length() - StringUtil.notNullize(oText).length(); if (byTextLength != 0) return byTextLength; - int byText = StringUtil.compare(myText, oText, true); - if (byText != 0) return byText; int byGroup = Comparing.compare(myGroupName, o.getGroupName()); if (byGroup != 0) return byGroup; int byDesc = StringUtil.compare(myPresentation.getDescription(), oPresentation.getDescription(), true);