From 9af5e6de4dcd55becb4895990f639930b4ca3cae Mon Sep 17 00:00:00 2001 From: "peter.gromov" Date: Fri, 12 Nov 2010 18:27:31 +0300 Subject: [PATCH] what appears at the top of the lookup, stays at the top of the lookup --- .../intellij/codeInsight/lookup/impl/LookupImpl.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index fab60030a8e6..d8f37935fcfa 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -91,6 +91,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { private boolean myDisposed = false; private boolean myHidden = false; private LookupElement myPreselectedItem = EMPTY_LOOKUP_ITEM; + private final List myFrozenItems = new ArrayList(); private String mySelectionInvariant = null; private boolean mySelectionTouched; private boolean myFocused = true; @@ -186,6 +187,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { @TestOnly public void resort() { mySelectionTouched = false; + myFrozenItems.clear(); myPreselectedItem = EMPTY_LOOKUP_ITEM; final List items = myModel.getItems(); myModel.clearItems(); @@ -261,6 +263,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { public void setAdditionalPrefix(final String additionalPrefix) { myAdditionalPrefix = additionalPrefix; myInitialPrefix = null; + myFrozenItems.clear(); refreshUi(); } @@ -270,6 +273,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { } if (myReused) { + myFrozenItems.clear(); myModel.collectGarbage(); myReused = false; } @@ -397,6 +401,12 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { } private void addMostRelevantItems(DefaultListModel model, Set firstItems, final Collection> sortedItems) { + for (LookupElement item : myFrozenItems) { + if (prefixMatches(item) && firstItems.add(item)) { + model.addElement(item); + } + } + for (final List elements : sortedItems) { final List suitable = new SmartList(); for (final LookupElement item : elements) { @@ -409,6 +419,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { for (final LookupElement item : suitable) { firstItems.add(item); model.addElement(item); + myFrozenItems.add(item); } } }