Result (@NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) { if (!(file instanceof YAMLFile) || !file.isValid()) { return Result.Continue; } if (!shouldInsertAutomaticHyphen(file)) { return Result.Continue; } int caretOffset = editor.getCaretModel().getOffset(); if (caretOffset <= 0) { // Actually it is magic situation return Result.Continue; } PsiElement element = file.findElementAt(caretOffset - 1); if (!YAMLElementTypes.BLANK_ELEMENTS.contains(PsiUtilCore.getElementType(element))) { return Result.Continue; } PsiElement parent = element.getParent(); IElementType parentType = PsiUtilCore.getElementType(parent); if (parentType != YAMLElementTypes.SEQUENCE) { if (parentType != YAMLElementTypes.MAPPING) { return Result.Continue; } PsiElement prevElem = element.getPrevSibling(); while (YAMLElementTypes.BLANK_ELEMENTS.contains(PsiUtilCore.getElementType(prevElem))) { prevElem = prevElem.getPrevSibling(); } if (PsiUtilCore.getElementType(prevElem) != YAMLElementTypes.KEY_VALUE_PAIR) { return Result.Continue; } if (PsiUtilCore.getElementType(prevElem.getLastChild()) != YAMLElementTypes.SEQUENCE) { return Result.Continue; } if (YAMLUtil.getIndentToThisElement(prevElem.getLastChild()) != YAMLUtil.getIndentToThisElement(parent)) { return Result.Continue; } } else { // don't insert a second '-' before already existing '-' PsiElement prevSibling = element.getPrevSibling(); if (isEmptySequenceItem(prevSibling)) { return Result.Continue; } while (YAMLElementTypes.BLANK_ELEMENTS.contains(PsiUtilCore.getElementType(prevSibling))) { prevSibling = prevSibling.getPrevSibling(); } if (PsiUtilCore.getElementType(prevSibling) == YAMLElementTypes.SEQUENCE_ITEM && PsiUtilCore.getElementType(prevSibling.getLastChild()) == YAMLElementTypes.MAPPING) { return Result.Continue; } } editor.getDocument().insertString(caretOffset, "- "); editor.getCaretModel().moveToOffset(caretOffset + 2); return Result.Stop; }