private boolean isAlreadyInTheEditor(LookupElement item) {
    Editor editor = lookup.getEditor();
    int start = editor.getCaretModel().getOffset() - lookup.itemPattern(item).length();
    Document document = editor.getDocument();
    return start >= 0 && StringUtil.startsWith(document.getImmutableCharSequence().subSequence(start, document.getTextLength()),
                                               item.getLookupString());
  }
private boolean isAlreadyInTheEditor(LookupElement item)