private void addListeners() {
    editor.getDocument().addDocumentListener(new DocumentListener() {
      @Override
      public void documentChanged(@NotNull DocumentEvent e) {
        if (canHide()) {
          hideLookup(false);
        }
      }
    }, this);

    final EditorMouseListener mouseListener = new EditorMouseListener() {
      @Override
      public void mouseClicked(@NotNull EditorMouseEvent e) {
        e.consume();
        hideLookup(false);
      }
    };

    editor.getCaretModel().addCaretListener(new CaretListener() {
      @Override
      public void caretPositionChanged(@NotNull CaretEvent e) {
        if (canHide()) {
          hideLookup(false);
        }
      }
    }, this);
    editor.getSelectionModel().addSelectionListener(new SelectionListener() {
      @Override
      public void selectionChanged(final @NotNull SelectionEvent e) {
        if (canHide()) {
          hideLookup(false);
        }
      }
    }, this);
    editor.addEditorMouseListener(mouseListener, this);

    JComponent editorComponent = editor.getContentComponent();
    if (editorComponent.isShowing()) {
      Disposer.register(this, UiNotifyConnector.installOn(editorComponent, new Activatable() {
        @Override
        public void hideNotify() {
          hideLookup(false);
        }
      }));

      Window window = ComponentUtil.getWindow(editorComponent);
      if (window != null) {
        ComponentListener windowListener = new ComponentAdapter() {
          @Override
          public void componentMoved(ComponentEvent event) {
            hideLookup(false);
          }
        };

        window.addComponentListener(windowListener);
        Disposer.register(this, () -> window.removeComponentListener(windowListener));
      }
    }

    list.addListSelectionListener(new ListSelectionListener() {
      private LookupElement oldItem = null;

      @Override
      public void valueChanged(@NotNull ListSelectionEvent e) {
        if (!myUpdating) {
          final LookupElement item = getCurrentItem();
          fireCurrentItemChanged(oldItem, item);
          oldItem = item;
        }
      }
    });

    new ClickListener() {
      @Override
      public boolean onClick(@NotNull MouseEvent e, int clickCount) {
        setLookupFocusDegree(LookupFocusDegree.FOCUSED);
        markSelectionTouched();
        if (ScreenReader.isActive()) {
          list.requestFocus();
        }
        else {
          editorComponent.requestFocus();
        }

        if (clickCount == 2) {
          CommandProcessor.getInstance()
            .executeCommand(project, () -> finishLookup(NORMAL_SELECT_CHAR), "", null, editor.getDocument());
        }
        return true;
      }
    }.installOn(list);

    addPrefixChangeListener(new PrefixChangeListener() {
      @Override
      public void afterAppend(char c) {
        cellRenderer.scheduleUpdateLookupWidthFromVisibleItems();
      }
    }, this);
  }
private void addListeners()