diff --git a/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereUI.java b/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereUI.java index 5f6812c00ac0..96f9ae0fec66 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereUI.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/searcheverywhere/SearchEverywhereUI.java @@ -1057,6 +1057,7 @@ public class SearchEverywhereUI extends BigPopupUI implements DataProvider, Quic if (resultsExpired) { retainContributors(itemsMap.keySet()); + clearMoreItems(); itemsMap.forEach((contributor, list) -> { Object[] oldItems = ArrayUtil.toObjectArray(getFoundItems(contributor)); @@ -1115,6 +1116,17 @@ public class SearchEverywhereUI extends BigPopupUI implements DataProvider, Quic } } + private void clearMoreItems() { + ListIterator iterator = listElements.listIterator(); + while (iterator.hasNext()) { + int index = iterator.nextIndex(); + if (iterator.next().getElement() == MORE_ELEMENT) { + iterator.remove(); + fireContentsChanged(this, index, index); + } + } + } + private void addElementsWithPriority(SearchEverywhereContributor contributor, int index, List newElements) { for (SESearcher.ElementInfo newElementInfo : newElements) { if (index < listElements.size()) { diff --git a/platform/lang-impl/testSources/com/intellij/ide/actions/searcheverywhere/SearchModelTest.java b/platform/lang-impl/testSources/com/intellij/ide/actions/searcheverywhere/SearchModelTest.java index b90300e6cadd..bddfc6019113 100644 --- a/platform/lang-impl/testSources/com/intellij/ide/actions/searcheverywhere/SearchModelTest.java +++ b/platform/lang-impl/testSources/com/intellij/ide/actions/searcheverywhere/SearchModelTest.java @@ -72,8 +72,39 @@ public class SearchModelTest extends LightPlatformCodeInsightFixtureTestCase { Assert.assertEquals(expectedItems, actualItems); // expiring results ----------------------------------------------------------------------- - // removing items ----------------------------------------------------------------------- + model.expireResults(); + model.addElements(Arrays.asList( + new SESearcher.ElementInfo("item_3_50", 310, STUB_CONTRIBUTOR_3), + new SESearcher.ElementInfo("item_1_20", 160, STUB_CONTRIBUTOR_1), + new SESearcher.ElementInfo("item_3_10", 350, STUB_CONTRIBUTOR_3), + new SESearcher.ElementInfo("item_2_23", 250, STUB_CONTRIBUTOR_2), + new SESearcher.ElementInfo("item_3_30", 330, STUB_CONTRIBUTOR_3), + new SESearcher.ElementInfo("item_2_05", 290, STUB_CONTRIBUTOR_2), + new SESearcher.ElementInfo("item_2_10", 280, STUB_CONTRIBUTOR_2), + new SESearcher.ElementInfo("item_1_35", 130, STUB_CONTRIBUTOR_1), + new SESearcher.ElementInfo("item_3_20", 340, STUB_CONTRIBUTOR_3), + new SESearcher.ElementInfo("item_1_25", 150, STUB_CONTRIBUTOR_1) + )); + model.setHasMore(STUB_CONTRIBUTOR_1, true); + model.setHasMore(STUB_CONTRIBUTOR_2, true); + actualItems = model.getItems(); + expectedItems = Arrays.asList("item_1_20", "item_1_25", "item_1_35", SearchListModel.MORE_ELEMENT, + "item_2_05", "item_2_10", "item_2_23", SearchListModel.MORE_ELEMENT, + "item_3_10", "item_3_20", "item_3_30", "item_3_50"); + Assert.assertEquals(expectedItems, actualItems); + + // removing items ----------------------------------------------------------------------- + model.removeElement("item_1_25", STUB_CONTRIBUTOR_1); + model.removeElement("item_3_20", STUB_CONTRIBUTOR_3); + model.removeElement("item_3_30", STUB_CONTRIBUTOR_3); + model.setHasMore(STUB_CONTRIBUTOR_1, false); + + actualItems = model.getItems(); + expectedItems = Arrays.asList("item_1_20", "item_1_35", + "item_2_05", "item_2_10", "item_2_23", SearchListModel.MORE_ELEMENT, + "item_3_10", "item_3_50"); + Assert.assertEquals(expectedItems, actualItems); } @NotNull