mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
preselect the most relevant item when lexicographic sorting is enabled in the lookups
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
class Foo {
|
||||
int ELEMENT_A = 1;
|
||||
int ELEMENT_B = 1;
|
||||
int ELEMENT_C = 1;
|
||||
int ELEMENT_D = 1;
|
||||
int ELEMENT_E = 1;
|
||||
int ELEMENT_F = 1;
|
||||
int ELEMENT_G = 1;
|
||||
int ELEMENT_H = 1;
|
||||
int ELEMENT_I = 1;
|
||||
|
||||
|
||||
{
|
||||
El<caret>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
|
||||
@@ -170,7 +171,8 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
|
||||
public void testDeclaredMembersGoFirst() throws Exception {
|
||||
invokeCompletion(getTestName(false) + ".java");
|
||||
assertStringItems("fromThis", "overridden", "fromSuper", "equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait", "wait", "wait");
|
||||
assertStringItems("fromThis", "overridden", "fromSuper", "equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait",
|
||||
"wait", "wait");
|
||||
}
|
||||
|
||||
public void testLocalVarsOverMethods() {
|
||||
@@ -246,6 +248,23 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
checkPreferredItems(0, "Bar9", "Bar1", "Bar2", "Bar3", "Bar4");
|
||||
}
|
||||
|
||||
public void testPreselectMostRelevantInTheMiddleAlpha() {
|
||||
UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = true;
|
||||
|
||||
try {
|
||||
myFixture.addClass("package foo; public class Elaaaaaaaaaaaaaaaaaaaa {}");
|
||||
invokeCompletion(getTestName(false) + ".java");
|
||||
myFixture.completeBasic();
|
||||
LookupImpl lookup = getLookup();
|
||||
assertPreferredItems(lookup.getList().getSelectedIndex());
|
||||
assertEquals("Elaaaaaaaaaaaaaaaaaaaa", lookup.getItems().get(0).getLookupString());
|
||||
assertEquals("ELEMENT_A", lookup.getCurrentItem().getLookupString());
|
||||
}
|
||||
finally {
|
||||
UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void testSortSameNamedVariantsByProximity() {
|
||||
myFixture.addClass("public class Bar {}");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
||||
@@ -32,23 +32,6 @@ public abstract class LookupArranger {
|
||||
return ClassifierFactory.listClassifier();
|
||||
}
|
||||
};
|
||||
public static final LookupArranger LEXICOGRAPHIC = new LookupArranger() {
|
||||
|
||||
@Override
|
||||
public Comparator<LookupElement> getItemComparator() {
|
||||
return new Comparator<LookupElement>() {
|
||||
@Override
|
||||
public int compare(LookupElement o1, LookupElement o2) {
|
||||
return o1.getLookupString().compareTo(o2.getLookupString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Classifier<LookupElement> createRelevanceClassifier() {
|
||||
return ClassifierFactory.sortingListClassifier(getItemComparator());
|
||||
}
|
||||
};
|
||||
|
||||
public void itemSelected(LookupElement item, final Lookup lookup) {
|
||||
}
|
||||
|
||||
@@ -396,9 +396,11 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
myFrozenItems.retainAll(items);
|
||||
model.addAll(myFrozenItems);
|
||||
|
||||
addMostRelevantItems(model, snapshot.second);
|
||||
if (hasPreselected) {
|
||||
model.add(myPreselectedItem);
|
||||
if (!isAlphaSorted()) {
|
||||
addMostRelevantItems(model, snapshot.second);
|
||||
if (hasPreselected) {
|
||||
model.add(myPreselectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
myPreferredItemsCount = model.size();
|
||||
@@ -407,9 +409,11 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
myFrozenItems.addAll(model);
|
||||
}
|
||||
|
||||
if (limitRelevance()) {
|
||||
if (isAlphaSorted()) {
|
||||
model.addAll(items);
|
||||
} else if (limitRelevance()) {
|
||||
model.addAll(addRemainingItemsLexicographically(model, items));
|
||||
} else {
|
||||
} else {
|
||||
for (List<LookupElement> group : snapshot.second) {
|
||||
for (LookupElement element : group) {
|
||||
if (prefixMatches(element)) {
|
||||
@@ -601,12 +605,13 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
|
||||
}
|
||||
|
||||
private LookupArranger getActualArranger() {
|
||||
if (isCompletion() && UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY) {
|
||||
return LookupArranger.LEXICOGRAPHIC;
|
||||
}
|
||||
return myCustomArranger;
|
||||
}
|
||||
|
||||
private boolean isAlphaSorted() {
|
||||
return isCompletion() && UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY;
|
||||
}
|
||||
|
||||
private boolean isExactPrefixItem(LookupElement item, final boolean caseSensitive) {
|
||||
final String pattern = itemPattern(item);
|
||||
final Set<String> strings = item.getAllLookupStrings();
|
||||
|
||||
Reference in New Issue
Block a user