void () { @Language("HTML") String text = """ <!doctype html> <html> <fieldset></fieldset> <select></select> <caret> </html>"""; final PsiFile file = configureByText(HtmlFileType.INSTANCE, text ); final XmlTag fieldSet = PsiTreeUtil.getParentOfType(file.findElementAt(file.getText().indexOf("fieldset")), XmlTag.class); assertNotNull(fieldSet); assertEquals("fieldset", fieldSet.getName()); final XmlTag select = PsiTreeUtil.getParentOfType(file.findElementAt(file.getText().indexOf("select")), XmlTag.class); assertNotNull(select); assertEquals("select", select.getName()); final SmartPsiElementPointer<XmlTag> fieldSetPointer = createPointer(fieldSet); final SmartPsiElementPointer<XmlTag> selectPointer = createPointer(select); WriteCommandAction.runWriteCommandAction(getProject(), () -> insertString(getEditor().getDocument(), getEditor().getCaretModel().getOffset(), "<a></a>")); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); final XmlTag newFieldSet = fieldSetPointer.getElement(); assertNotNull(newFieldSet); assertEquals("fieldset", newFieldSet.getName()); final XmlTag newSelect = selectPointer.getElement(); assertNotNull(newSelect); assertEquals("select", newSelect.getName()); }