diff --git a/java/java-tests/testSrc/com/intellij/java/navigation/ChooseByNameTest.groovy b/java/java-tests/testSrc/com/intellij/java/navigation/ChooseByNameTest.groovy index 197e86050d6c..7f963b7a2143 100644 --- a/java/java-tests/testSrc/com/intellij/java/navigation/ChooseByNameTest.groovy +++ b/java/java-tests/testSrc/com/intellij/java/navigation/ChooseByNameTest.groovy @@ -22,6 +22,7 @@ import com.intellij.openapi.Disposable import com.intellij.openapi.application.ModalityState import com.intellij.openapi.util.Disposer import com.intellij.psi.CommonClassNames +import com.intellij.psi.PsiClass import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.search.ProjectScope @@ -154,12 +155,12 @@ class Intf { assert elements == files } - void "test middle matching for directories"() { + void "test middle matching for files and directories"() { def fooIndex = myFixture.addFileToProject("foo/index.html", "foo") def ooIndex = myFixture.addFileToProject("oo/index.html", "oo") def fooBarIndex = myFixture.addFileToProject("foo/bar/index.html", "foo bar") - def elements = getPopupElements(new GotoFileModel(project), "oo/index") - assert elements == [ooIndex, fooIndex, fooBarIndex] + assert getPopupElements(new GotoFileModel(project), "oo/index") == [ooIndex, fooIndex, fooBarIndex] + assert getPopupElements(new GotoFileModel(project), "ndex.html") == [fooIndex, ooIndex, fooBarIndex] } void "test prefer files from current directory"() { @@ -394,6 +395,12 @@ class Intf { assert calcPopupElements(popup, "somefb\\index.html") == [someFbFile] } + void "test fix keyboard layout"() { + assert (getPopupElements(new GotoClassModel2(project), 'Ыекштп')[0] as PsiClass).name == 'String' + assert (getPopupElements(new GotoSymbolModel2(project), 'Ыекштп')[0] as PsiClass).name == 'String' + assert (getPopupElements(new GotoFileModel(project), 'Ыекштп')[0] as PsiFile).name == 'String.class' + } + void "test prefer exact case match"() { def upper = myFixture.addClass("class SOMECLASS {}") def camel = myFixture.addClass("class SomeClass {}") diff --git a/platform/lang-impl/src/com/intellij/ide/actions/GotoFileItemProvider.java b/platform/lang-impl/src/com/intellij/ide/actions/GotoFileItemProvider.java index c86333b32857..4b38ab3e8cc9 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/GotoFileItemProvider.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/GotoFileItemProvider.java @@ -28,6 +28,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFileSystemItem; import com.intellij.psi.PsiManager; +import com.intellij.psi.codeStyle.FixingLayoutMatcher; import com.intellij.psi.codeStyle.MinusculeMatcher; import com.intellij.psi.codeStyle.NameUtil; import com.intellij.util.Processor; @@ -162,6 +163,7 @@ public class GotoFileItemProvider extends DefaultChooseByNameItemProvider { private class NameGrouper { private final String namePattern; + @Nullable private final String alternativePattern; /** Names placed into buckets where the index of bucket == {@link #findMatchStartingPosition} */ private final List> candidateNames; @@ -170,12 +172,16 @@ public class GotoFileItemProvider extends DefaultChooseByNameItemProvider { NameGrouper(@NotNull String namePattern) { this.namePattern = namePattern; + alternativePattern = FixingLayoutMatcher.fixLayout(namePattern); candidateNames = IntStreamEx.range(0, namePattern.length()).mapToObj(__ -> (List)new ArrayList()).toList(); } boolean processName(String name) { ProgressManager.checkCanceled(); int position = findMatchStartingPosition(name, namePattern); + if (position >= namePattern.length() && alternativePattern != null) { + position = findMatchStartingPosition(name, alternativePattern); + } if (position < namePattern.length()) { List list = candidateNames.get(position); //noinspection SynchronizationOnLocalVariableOrMethodParameter