コード例 #1
0
 private static void addCurrentlySelectedItemToTop(
     Lookup lookup, List<LookupElement> items, LinkedHashSet<LookupElement> model) {
   if (!lookup.isSelectionTouched()) {
     LookupElement lastSelection = lookup.getCurrentItem();
     if (ContainerUtil.indexOfIdentity(items, lastSelection) >= 0) {
       model.add(lastSelection);
     }
   }
 }
コード例 #2
0
  private static int getItemToSelect(
      LookupImpl lookup,
      List<LookupElement> items,
      boolean onExplicitAction,
      @Nullable LookupElement mostRelevant) {
    if (items.isEmpty() || lookup.getFocusDegree() == LookupImpl.FocusDegree.UNFOCUSED) {
      return 0;
    }

    if (lookup.isSelectionTouched() || !onExplicitAction) {
      final LookupElement lastSelection = lookup.getCurrentItem();
      int old = ContainerUtil.indexOfIdentity(items, lastSelection);
      if (old >= 0) {
        return old;
      }

      Object selectedValue = ((LookupImpl) lookup).getList().getSelectedValue();
      if (selectedValue instanceof EmptyLookupItem
          && ((EmptyLookupItem) selectedValue).isLoading()) {
        int index = ((LookupImpl) lookup).getList().getSelectedIndex();
        if (index >= 0 && index < items.size()) {
          return index;
        }
      }

      for (int i = 0; i < items.size(); i++) {
        String invariant = PRESENTATION_INVARIANT.get(items.get(i));
        if (invariant != null && invariant.equals(PRESENTATION_INVARIANT.get(lastSelection))) {
          return i;
        }
      }
    }

    String selectedText = lookup.getEditor().getSelectionModel().getSelectedText();
    for (int i = 0; i < items.size(); i++) {
      LookupElement item = items.get(i);
      if (isPrefixItem(lookup, item, true) && !isLiveTemplate(item)
          || item.getLookupString().equals(selectedText)) {
        return i;
      }
    }

    return Math.max(0, ContainerUtil.indexOfIdentity(items, mostRelevant));
  }
コード例 #3
0
 private static void ensureItemAdded(
     List<LookupElement> items,
     LinkedHashSet<LookupElement> model,
     Iterator<LookupElement> byRelevance,
     @Nullable final LookupElement item) {
   if (item != null && ContainerUtil.indexOfIdentity(items, item) >= 0 && !model.contains(item)) {
     addSomeItems(
         model,
         byRelevance,
         new Condition<LookupElement>() {
           @Override
           public boolean value(LookupElement lastAdded) {
             return lastAdded == item;
           }
         });
   }
 }
コード例 #4
0
 protected void silentlyReplaceItem(@NotNull T oldItem, @NotNull T newItem, int index) {
   // silently replace item
   List<T> items = getItems();
   items.set(index == -1 ? ContainerUtil.indexOfIdentity(items, oldItem) : index, newItem);
 }