boolean (HtmlFileImpl target, VirtualFile droppedFile, Editor editor, String tagTemplate) { final String relativePath = getRelativePath(target, droppedFile); final String tagText = prepareTagText(target, tagTemplate, relativePath); final XmlDocument document = target.getDocument(); if (document == null || tagText == null) return false; final XmlTag[] topLevelTags = PsiTreeUtil.getChildrenOfType(document, XmlTag.class); XmlTag html = null; XmlTag head = null; if (topLevelTags != null) { for (XmlTag tag : topLevelTags) { if ("html".equals(tag.getName())) { html = tag; break; } if ("head".equals(tag.getName())) { head = tag; break; } } } if (html != null) { head = html.findFirstSubTag("head"); } final PsiElement parent = head != null ? head : html != null ? html : document; if (checkIfPresent(editor, tagTemplate, relativePath, parent)) return true; WriteCommandAction.writeCommandAction(target.getProject(), target).run(() -> { final XmlTag tag = XmlElementFactory.getInstance(target.getProject()).createHTMLTagFromText(tagText); if (parent instanceof XmlTag) { ((XmlTag)parent).addSubTag(tag, !"head".equals(((XmlTag)parent).getName())); } else { parent.addAfter(tag, ((XmlDocument)parent).getProlog()); } }); return true; }