mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
skip enumerated, fixed and attributes with known value (WEB-307, WEB-15805)
This commit is contained in:
@@ -15,11 +15,14 @@
|
||||
*/
|
||||
package com.intellij.spellchecker.tokenizer;
|
||||
|
||||
import com.intellij.codeInsight.completion.HtmlCompletionContributor;
|
||||
import com.intellij.psi.ElementManipulators;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import com.intellij.xml.XmlAttributeDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HtmlSpellcheckingStrategy extends SpellcheckingStrategy {
|
||||
@@ -31,6 +34,18 @@ public class HtmlSpellcheckingStrategy extends SpellcheckingStrategy {
|
||||
if (URLUtil.isDataUri(ElementManipulators.getValueText(element))) {
|
||||
return EMPTY_TOKENIZER;
|
||||
}
|
||||
PsiElement parent = element.getParent();
|
||||
if (parent instanceof XmlAttribute) {
|
||||
if (HtmlCompletionContributor.hasHtmlAttributesCompletion(element) &&
|
||||
HtmlCompletionContributor.addSpecificCompletions((XmlAttribute)parent).length > 0) {
|
||||
return EMPTY_TOKENIZER;
|
||||
}
|
||||
XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
|
||||
if (descriptor != null && (descriptor.isEnumerated() || descriptor.isFixed())) {
|
||||
return EMPTY_TOKENIZER;
|
||||
}
|
||||
}
|
||||
|
||||
return myXmlAttributeTokenizer;
|
||||
}
|
||||
return EMPTY_TOKENIZER;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<div>
|
||||
<a target="_blank" rel="nofollow"></a>
|
||||
<a rel="noopener"></a>
|
||||
<ul role="tablist"></ul>
|
||||
</div>
|
||||
@@ -31,4 +31,8 @@ public class XmlWithMistakesInspectionTest extends SpellcheckerInspectionTestCas
|
||||
public void testCharacterData() {
|
||||
doTest("test.html");
|
||||
}
|
||||
|
||||
public void testKnownAttributes() {
|
||||
doTest("attributes.html");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,18 @@ import static com.intellij.html.impl.util.MicrodataUtil.*;
|
||||
import static com.intellij.patterns.PlatformPatterns.psiElement;
|
||||
|
||||
public class HtmlCompletionContributor extends CompletionContributor implements DumbAware {
|
||||
|
||||
public static final String[] TARGET = {"_blank", "_top", "_self", "_parent"};
|
||||
public static final String[] ENCTYPE = {"multipart/form-data", "application/x-www-form-urlencoded"};
|
||||
public static final String[] REL = {"alternate", "author", "bookmark", "help", "icon", "license", "next", "nofollow",
|
||||
"noreferrer", "noopener", "prefetch", "prev", "search", "stylesheet", "tag", "start", "contents", "index",
|
||||
"glossary", "copyright", "chapter", "section", "subsection", "appendix", "script", "import",
|
||||
"apple-touch-icon", "apple-touch-icon-precomposed", "apple-touch-startup-image"};
|
||||
public static final String[] MEDIA = {"all", "braille", "embossed", "handheld", "print", "projection", "screen", "speech", "tty", "tv"};
|
||||
public static final String[] LANGUAGE =
|
||||
{"JavaScript", "VBScript", "JScript", "JavaScript1.2", "JavaScript1.3", "JavaScript1.4", "JavaScript1.5"};
|
||||
public static final String[] TYPE = {"text/css", "text/html", "text/plain", "text/xml"};
|
||||
|
||||
public HtmlCompletionContributor() {
|
||||
extend(CompletionType.BASIC, psiElement().inside(XmlPatterns.xmlAttributeValue()), new CompletionProvider<CompletionParameters>() {
|
||||
@Override
|
||||
@@ -76,7 +88,7 @@ public class HtmlCompletionContributor extends CompletionContributor implements
|
||||
|
||||
@NotNull
|
||||
@NonNls
|
||||
protected static String[] addSpecificCompletions(final XmlAttribute attribute) {
|
||||
public static String[] addSpecificCompletions(final XmlAttribute attribute) {
|
||||
@NonNls String name = attribute.getName();
|
||||
final XmlTag tag = attribute.getParent();
|
||||
if (tag == null) return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
@@ -91,25 +103,22 @@ public class HtmlCompletionContributor extends CompletionContributor implements
|
||||
if (XmlUtil.XHTML_URI.equals(namespace) || XmlUtil.HTML_URI.equals(namespace)) {
|
||||
|
||||
if ("target".equals(name)) {
|
||||
return new String[]{"_blank", "_top", "_self", "_parent"};
|
||||
return TARGET;
|
||||
}
|
||||
else if ("enctype".equals(name)) {
|
||||
return new String[]{"multipart/form-data", "application/x-www-form-urlencoded"};
|
||||
return ENCTYPE;
|
||||
}
|
||||
else if ("rel".equals(name) || "rev".equals(name)) {
|
||||
return new String[]{"alternate", "author", "bookmark", "help", "icon", "license", "next", "nofollow",
|
||||
"noreferrer", "noopener", "prefetch", "prev", "search", "stylesheet", "tag", "start", "contents", "index",
|
||||
"glossary", "copyright", "chapter", "section", "subsection", "appendix", "script", "import",
|
||||
"apple-touch-icon", "apple-touch-icon-precomposed", "apple-touch-startup-image"};
|
||||
return REL;
|
||||
}
|
||||
else if ("media".equals(name)) {
|
||||
return new String[]{ "all", "braille", "embossed", "handheld", "print", "projection", "screen", "speech", "tty", "tv" };
|
||||
return MEDIA;
|
||||
}
|
||||
else if ("language".equals(name)) {
|
||||
return new String[]{"JavaScript", "VBScript", "JScript", "JavaScript1.2", "JavaScript1.3", "JavaScript1.4", "JavaScript1.5"};
|
||||
return LANGUAGE;
|
||||
}
|
||||
else if ("type".equals(name) && "link".equals(tagName)) {
|
||||
return new String[]{"text/css", "text/html", "text/plain", "text/xml"};
|
||||
return TYPE;
|
||||
}
|
||||
else if ("http-equiv".equals(name) && "meta".equals(tagName)) {
|
||||
return HtmlUtil.RFC2616_HEADERS;
|
||||
|
||||
Reference in New Issue
Block a user