InsertHandler<LookupElement> (@NotNull VcsRef item) { return (context, item1) -> { mySelectedRef = (VcsRef)item1.getObject(); ApplicationManager.getApplication().invokeLater(() -> { // handleInsert is called in the middle of some other code that works with editor // (see CodeCompletionHandlerBase.insertItem) // for example, scrolls editor // problem is that in onOk we make text field not editable // by some reason this is done by disposing its editor and creating a new one // so editor gets disposed here and CodeCompletionHandlerBase can not finish doing whatever it is doing with it // I counter this by invoking onOk in invokeLater myTextField.onOk(); }); }; }