InsertHandler<LookupElement> (@NotNull final Task task) { return new InsertHandler<>() { @Override public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) { Document document = context.getEditor().getDocument(); String s = ((TaskManagerImpl)TaskManager.getManager(context.getProject())).getChangelistName(task); s = StringUtil.convertLineSeparators(s); document.replaceString(context.getStartOffset(), context.getTailOffset(), s); context.getEditor().getCaretModel().moveToOffset(context.getStartOffset() + s.length()); TaskAutoCompletionListProvider.this.handleInsert(task); } }; }