Merge remote-tracking branch 'origin/master'
authorYann Cébron <yann.cebron@jetbrains.com>
Wed, 28 Oct 2015 17:21:14 +0000 (18:21 +0100)
committerYann Cébron <yann.cebron@jetbrains.com>
Wed, 28 Oct 2015 17:21:14 +0000 (18:21 +0100)
java/java-tests/testSrc/com/intellij/navigation/GotoActionTest.groovy
platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java

index 9e56995d0eddae5f4c5b1c17dc45e98e0f595490..0919e3ff88219e5bcd52c42618ad493c73541945 100644 (file)
  * limitations under the License.
  */
 package com.intellij.navigation
+
 import com.intellij.ide.util.gotoByName.GotoActionModel
 import com.intellij.openapi.actionSystem.AnAction
 import com.intellij.openapi.actionSystem.AnActionEvent
 import com.intellij.openapi.actionSystem.DataContext
 import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
+
 /**
  * @author peter
  */
@@ -28,17 +30,34 @@ class GotoActionTest extends LightCodeInsightFixtureTestCase {
     def pattern = 'Rebas'
     def fork = 'Rebase my GitHub fork'
     def rebase = 'Rebase...'
-    def items = [new GotoActionModel.MatchedValue(createAction(fork), pattern), new GotoActionModel.MatchedValue(createAction(rebase), pattern)].sort()
+    def items = [matchedValue(fork, pattern),
+                 matchedValue(rebase, pattern)].sort()
     assert [rebase, fork] == items.collect { it.valueText }
   }
 
-  private static GotoActionModel.ActionWrapper createAction(String text) {
+  public void "test sort by match mode"() {
+    def pattern = 'by'
+    def byName = 'By Name'
+    def byDesc = 'By Desc'
+    def items = [matchedValue(byName, pattern),
+                 matchedValue(byDesc, pattern, GotoActionModel.MatchMode.DESCRIPTION)].sort()
+    assert [byName, byDesc] == items.collect { it.valueText }
+  }
+  
+  static def matchedValue(String fork, String pattern) {
+    matchedValue(fork, pattern, GotoActionModel.MatchMode.NAME)
+  }
+
+  static def matchedValue(String fork, String pattern, GotoActionModel.MatchMode mode) {
+    new GotoActionModel.MatchedValue(createAction(fork, mode), pattern)
+  }
+
+  static def createAction(String text, GotoActionModel.MatchMode mode) {
     def action = new AnAction(text) {
       @Override
       void actionPerformed(AnActionEvent e) {
       }
     }
-    return new GotoActionModel.ActionWrapper(action, "", GotoActionModel.MatchMode.NAME, DataContext.EMPTY_CONTEXT)
+    new GotoActionModel.ActionWrapper(action, "", mode, DataContext.EMPTY_CONTEXT)
   }
-
 }
index 2fc6f82b0dd6fe32df8368fc23231c9e79324cb8..7b5088870f3e2656a3ac61a1944cd21ff95fba7b 100644 (file)
@@ -598,10 +598,14 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel, C
       if (compared != 0) return compared;
       Presentation myPresentation = myAction.getTemplatePresentation();
       Presentation oPresentation = o.getAction().getTemplatePresentation();
-      int byText = StringUtil.compare(myPresentation.getText(), oPresentation.getText(), true);
+      String myText = myPresentation.getText();
+      String oText = oPresentation.getText();
+      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;
+      if (byGroup != 0) return byGroup;
       int byDesc = StringUtil.compare(myPresentation.getDescription(), oPresentation.getDescription(), true);
       if (byDesc != 0) return byDesc;
       return 0;