@Override
    public void activeLookupChanged(@Nullable Lookup oldLookup,
                                    @Nullable Lookup newLookup) {
      if (newLookup instanceof LookupImpl lookup && shouldTryDeselectingFirstPopupItem(newLookup.getPsiElement())) {
        lookup.setPrefixChangeListener(new PrefixChangeListener() {
          @Override
          public void afterAppend(char c) {
            // Select first item when two chars are typed after '&'
            if (lookup.getCurrentItemOrEmpty() == null && hasTwoCharsAfterAmp(lookup)) {
              lookup.setSelectedIndex(0);
            }
          }
        });
        lookup.addLookupListener(new LookupListener() {
          @Override
          public void uiRefreshed() {
            var currentCompletion = getCompletionService().getCurrentCompletion();
            if (currentCompletion != null
                && currentCompletion.isAutopopupCompletion()
                && !lookup.isSelectionTouched()
                && !hasTwoCharsAfterAmp(lookup)) {
              // Deselect topmost item
              lookup.getList().setSelectedValue(null, false);
              ListSelectionModel selectionModel = lookup.getList().getSelectionModel();
              selectionModel.setAnchorSelectionIndex(-1);
              selectionModel.setLeadSelectionIndex(-1);
            }
          }
        });
      }
    }
@Override
    public void activeLookupChanged(@Nullable Lookup oldLookup,
                                    @Nullable Lookup newLookup)