LookupElement (LookupElement element) { return new LookupElementDecorator<>(element) { @Override public void handleInsert(@NotNull InsertionContext context) { PsiStatement statement = PsiTreeUtil.getParentOfType(context.getFile().findElementAt(context.getStartOffset()), PsiStatement.class); boolean isAfterArrow = false; if (statement != null) { if (statement.getParent() instanceof PsiCodeBlock) { PsiElement prevLeaf = PsiTreeUtil.prevCodeLeaf(statement); if (PsiUtil.isJavaToken(prevLeaf, JavaTokenType.ARROW) && prevLeaf.getParent() instanceof PsiSwitchLabeledRuleStatement) { isAfterArrow = true; } } else if (statement.getParent() instanceof PsiSwitchLabeledRuleStatement) { isAfterArrow = true; } } if (isAfterArrow) { CaretModel model = context.getEditor().getCaretModel(); int origPos = model.getOffset(); int start = statement.getTextRange().getStartOffset(); PsiStatement updatedStatement = BlockUtils.expandSingleStatementToBlockStatement(statement); int updatedStart = updatedStatement.getTextRange().getStartOffset(); model.moveToOffset(origPos + updatedStart - start); PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument()); context.setTailOffset(model.getOffset()); } super.handleInsert(context); } }; }