EditorModificationUtil.moveCaretRelatively(editor, 1);
++offset;
if (DocumentUtils.getCharAt(document, offset - 2) == '/') {
return false;
}
HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset - 2);
while (!iterator.atEnd() && !iterator.getTokenType().equals(CfmlTokenTypes.CF_TAG_NAME)) {
if (CfmlUtil.isControlToken(iterator.getTokenType())) {
return false;
}
iterator.retreat();
}
if (!iterator.atEnd()) {
iterator.retreat();
if (!iterator.atEnd() && iterator.getTokenType().equals(CfmlTokenTypes.LSLASH_ANGLEBRACKET)) {
return false;
}
iterator.advance();
}
if (iterator.atEnd()) {
return false;
}
String tagName = document.getCharsSequence().subSequence(iterator.getStart(), iterator.getEnd()).toString();
if (CfmlUtil.isSingleCfmlTag(tagName, project) || CfmlUtil.isUserDefined(tagName)) {
return false;
}
PsiElement tagElement = file.findElementAt(iterator.getStart());
while (tagElement != null && !(tagElement instanceof CfmlTag)) {
tagElement = tagElement.getParent();
}
if (tagElement == null) {
return false;
}
boolean doInsertion = false;
if (tagElement.getLastChild() instanceof PsiErrorElement) {
doInsertion = true;
}
else {
iterator = ((EditorEx)editor).getHighlighter().createIterator(0);
while (!iterator.atEnd() && iterator.getStart() < offset) {
if (iterator.getTokenType() == CfmlTokenTypes.CF_TAG_NAME) {
String currentTagName = document.getCharsSequence().subSequence(iterator.getStart(), iterator.getEnd()).toString();
if (tagName.equals(currentTagName)) {
PsiElement currentTagElement = file.findElementAt(iterator.getStart());
currentTagElement = PsiTreeUtil.getParentOfType(currentTagElement, CfmlTag.class);
if (currentTagElement.getLastChild() instanceof PsiErrorElement) {
doInsertion = true;
break;
}
}
}
iterator.advance();
}
}
if (doInsertion && CfmlUtil.isEndTagRequired(((CfmlTag)tagElement).getTagName(), project)) {
EditorModificationUtil.insertStringAtCaret(editor, "</" + ((CfmlTag)tagElement).getTagName() + ">", true, 0);
return true;