TextRange (@NotNull PsiElement element) { YAMLAnchor[] anchors = PsiTreeUtil.getChildrenOfType(element, YAMLAnchor.class); if (anchors != null && anchors.length > 0) { YAMLAnchor lastAnchor = anchors[anchors.length - 1]; PsiElement next = PsiTreeUtil.skipWhitespacesAndCommentsForward(lastAnchor); return next == null ? element.getTextRange() : next.getTextRange(); } PsiElement parent = element.getParent(); if (parent instanceof YAMLDocument) { PsiElement firstYamlChild = element.getFirstChild(); while (firstYamlChild != null && !(firstYamlChild instanceof YAMLPsiElement)) { firstYamlChild = firstYamlChild.getNextSibling(); } return firstYamlChild == null ? element.getTextRange() : firstYamlChild.getTextRange(); } return element.getTextRange(); }