mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
disable "remove extra closing tag" intention when it would do nothing
This commit is contained in:
+8
-14
@@ -34,6 +34,8 @@ import com.intellij.psi.xml.XmlToken;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author spleaner
|
||||
*/
|
||||
@@ -53,18 +55,14 @@ public class RemoveExtraClosingTagIntentionAction implements LocalQuickFix, Inte
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) {
|
||||
return true;
|
||||
PsiElement psiElement = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
return psiElement instanceof XmlToken &&
|
||||
(psiElement.getParent() instanceof XmlTag || psiElement.getParent() instanceof PsiErrorElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
final PsiElement psiElement = file.findElementAt(offset);
|
||||
if (psiElement == null || !psiElement.isValid() || !(psiElement instanceof XmlToken)) {
|
||||
return;
|
||||
}
|
||||
|
||||
doFix(psiElement);
|
||||
doFix(Objects.requireNonNull(file.findElementAt(editor.getCaretModel().getOffset())).getParent());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,11 +70,7 @@ public class RemoveExtraClosingTagIntentionAction implements LocalQuickFix, Inte
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void doFix(@NotNull final PsiElement element) throws IncorrectOperationException {
|
||||
final XmlToken endNameToken = (XmlToken)element;
|
||||
final PsiElement tagElement = endNameToken.getParent();
|
||||
if (!(tagElement instanceof XmlTag) && !(tagElement instanceof PsiErrorElement)) return;
|
||||
|
||||
private static void doFix(@NotNull PsiElement tagElement) throws IncorrectOperationException {
|
||||
if (tagElement instanceof PsiErrorElement) {
|
||||
tagElement.delete();
|
||||
}
|
||||
@@ -85,7 +79,7 @@ public class RemoveExtraClosingTagIntentionAction implements LocalQuickFix, Inte
|
||||
if (astNode != null) {
|
||||
final ASTNode endTagStart = XmlChildRole.CLOSING_TAG_START_FINDER.findChild(astNode);
|
||||
if (endTagStart != null) {
|
||||
final Document document = PsiDocumentManager.getInstance(element.getProject()).getDocument(tagElement.getContainingFile());
|
||||
final Document document = PsiDocumentManager.getInstance(tagElement.getProject()).getDocument(tagElement.getContainingFile());
|
||||
if (document != null) {
|
||||
document.deleteString(endTagStart.getStartOffset(), tagElement.getLastChild().getTextRange().getEndOffset());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user