IDEA-207411 Search Everywhere: Add sorting by element priority

This commit is contained in:
Mikhail Sokolov
2019-02-21 13:03:59 +03:00
parent e189f7b1dc
commit 5f5677e8d9
2 changed files with 44 additions and 1 deletions
@@ -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<SESearcher.ElementInfo> 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<SESearcher.ElementInfo> newElements) {
for (SESearcher.ElementInfo newElementInfo : newElements) {
if (index < listElements.size()) {
@@ -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