mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
WEB-15620 Custom html attributes and elements are added lowercase only
GitOrigin-RevId: 9051538795501005b181af53e9e5db4061544c92
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b0e5d3bec8
commit
c9ef2330da
@@ -1 +1 @@
|
||||
<div zzz="<caret>"
|
||||
<div zZz="<caret>"
|
||||
@@ -1 +1 @@
|
||||
<aaa zzz="<caret>"
|
||||
<aaa zZz="<caret>"
|
||||
@@ -1,3 +1,3 @@
|
||||
<div>
|
||||
<zzz><caret></zzz>
|
||||
<zZz><caret></zZz>
|
||||
</div>
|
||||
@@ -1 +1 @@
|
||||
<zzz<caret>
|
||||
<zZz<caret>
|
||||
@@ -1,2 +1,3 @@
|
||||
<<symbolName descr="Custom tag name">custom-tag</symbolName>>hello</<symbolName descr="Custom tag name">custom-tag</symbolName>>
|
||||
<<symbolName descr="Custom tag name">custom2-tag</symbolName>>hello</<symbolName descr="Custom tag name">custom2-tag</symbolName>>
|
||||
<custom-utag>hello</custom-utag>
|
||||
@@ -338,12 +338,8 @@ public class HtmlCompletionTest extends BasePlatformTestCase {
|
||||
|
||||
public void testAdditionalHtmlTagsInsertedByCompletion() throws Exception {
|
||||
final HtmlUnknownTagInspection inspection = new HtmlUnknownTagInspection();
|
||||
String additionalEntries = inspection.getAdditionalEntries();
|
||||
if (additionalEntries.length() > 0) {
|
||||
additionalEntries += ",";
|
||||
}
|
||||
|
||||
inspection.updateAdditionalEntries(additionalEntries + "zzz");
|
||||
inspection.updateAdditionalEntries("zZz", getTestRootDisposable());
|
||||
|
||||
doTestWithHtmlInspectionEnabled("", inspection);
|
||||
doTestWithHtmlInspectionEnabled("2", inspection);
|
||||
@@ -351,12 +347,8 @@ public class HtmlCompletionTest extends BasePlatformTestCase {
|
||||
|
||||
public void testAdditionalHtmlAttributesInsertedByCompletion() throws Exception {
|
||||
final HtmlUnknownAttributeInspection inspection = new HtmlUnknownAttributeInspection();
|
||||
String additionalEntries = inspection.getAdditionalEntries();
|
||||
if (additionalEntries.length() > 0) {
|
||||
additionalEntries += ",";
|
||||
}
|
||||
|
||||
inspection.updateAdditionalEntries(additionalEntries + "zzz");
|
||||
inspection.updateAdditionalEntries("zZz", getTestRootDisposable());
|
||||
|
||||
doTestWithHtmlInspectionEnabled("2", inspection);
|
||||
doTestWithHtmlInspectionEnabled("", inspection);
|
||||
|
||||
@@ -855,18 +855,12 @@ public class HtmlHighlightingTest extends BasePlatformTestCase {
|
||||
|
||||
public void testCustomTagHighlighting() {
|
||||
HtmlUnknownTagInspection inspection = new HtmlUnknownTagInspection();
|
||||
String before = inspection.getAdditionalEntries();
|
||||
inspection.updateAdditionalEntries("custom-tag,custom2-tag");
|
||||
try {
|
||||
myFixture.enableInspections(inspection);
|
||||
inspection.updateAdditionalEntries("custom-tag,custom2-TAG", getTestRootDisposable());
|
||||
myFixture.enableInspections(inspection);
|
||||
|
||||
HighlightTestInfo info = myFixture.testFile(getTestName(false) + ".html");
|
||||
info.checkSymbolNames();
|
||||
info.test();
|
||||
}
|
||||
finally {
|
||||
inspection.updateAdditionalEntries(before);
|
||||
}
|
||||
HighlightTestInfo info = myFixture.testFile(getTestName(false) + ".html");
|
||||
info.checkSymbolNames();
|
||||
info.test();
|
||||
}
|
||||
|
||||
private void doTestWebLinks(boolean startTestingLocalServer) throws Exception {
|
||||
|
||||
@@ -55,7 +55,7 @@ public class HtmlEmmetAbbreviationTest extends EmmetAbbreviationTestSuite {
|
||||
|
||||
@Override
|
||||
protected void setUp(@NotNull Project project) throws Exception {
|
||||
super.setUp(project);
|
||||
super.setUp(project);
|
||||
final TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(project);
|
||||
TemplateContextType contextType = TemplateContextTypes.getByClass(HtmlTextContextType.class);
|
||||
|
||||
@@ -222,10 +222,8 @@ public class HtmlEmmetAbbreviationTest extends EmmetAbbreviationTestSuite {
|
||||
addTestWithInit("input[title]", "<input type=\"text\" title=\"\">", null);
|
||||
addTestWithInit("input[title]", "<input type=\"text\" title>", (fixture, testRootDisposable) -> {
|
||||
final HtmlUnknownBooleanAttributeInspection inspection = new HtmlUnknownBooleanAttributeInspection();
|
||||
final String oldValue = inspection.getAdditionalEntries();
|
||||
inspection.updateAdditionalEntries("title");
|
||||
inspection.updateAdditionalEntries("title", testRootDisposable);
|
||||
fixture.enableInspections(inspection);
|
||||
Disposer.register(testRootDisposable, () -> inspection.updateAdditionalEntries(oldValue));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,15 @@ import com.intellij.codeInspection.ProblemHighlightType;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.util.InspectionMessage;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.JDOMExternalizableStringList;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlChildRole;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
@@ -43,7 +46,7 @@ public abstract class HtmlUnknownElementInspection extends HtmlLocalInspectionTo
|
||||
|
||||
final StringTokenizer tokenizer = new StringTokenizer(properties, ",");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
result.add(StringUtil.toLowerCase(tokenizer.nextToken()).trim());
|
||||
result.add(tokenizer.nextToken());
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -64,13 +67,13 @@ public abstract class HtmlUnknownElementInspection extends HtmlLocalInspectionTo
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isCustomValue(@NotNull final String value) {
|
||||
return myValues.contains(StringUtil.toLowerCase(value));
|
||||
protected boolean isCustomValue(@NotNull String value) {
|
||||
return ContainerUtil.exists(myValues, val -> StringUtil.equalsIgnoreCase(val, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEntry(@NotNull final String text) {
|
||||
final String s = StringUtil.toLowerCase(text.trim());
|
||||
final String s = text.trim();
|
||||
if (!isCustomValue(s)) {
|
||||
myValues.add(s);
|
||||
}
|
||||
@@ -89,8 +92,14 @@ public abstract class HtmlUnknownElementInspection extends HtmlLocalInspectionTo
|
||||
return StringUtil.join(myValues, ",");
|
||||
}
|
||||
|
||||
public void updateAdditionalEntries(@NotNull final String values) {
|
||||
public void updateAdditionalEntries(@NotNull final String values, Disposable disposable) {
|
||||
JDOMExternalizableStringList oldValue = myValues;
|
||||
myValues = reparseProperties(values);
|
||||
if (disposable != null) {
|
||||
Disposer.register(disposable, () -> {
|
||||
myValues = oldValue;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -63,9 +63,11 @@ class XmlCustomTagHighlightingPass(val file: PsiFile, editor: Editor) : TextEdit
|
||||
})
|
||||
}
|
||||
|
||||
private fun getCustomNames() = (HtmlUtil.getEntitiesString(file, XmlEntitiesInspection.TAG_SHORT_NAME)
|
||||
?.let { StringUtil.split(it, ",").toSet() }
|
||||
?: emptySet())
|
||||
private fun getCustomNames() =
|
||||
HtmlUtil.getEntitiesString(file, XmlEntitiesInspection.TAG_SHORT_NAME)
|
||||
?.splitToSequence(',')
|
||||
?.mapTo(HashSet()) { StringUtil.toLowerCase(it) }
|
||||
?: emptySet()
|
||||
|
||||
private fun applyHighlighting(node: ASTNode, elementType: IElementType) {
|
||||
if (node !is LeafElement) return
|
||||
@@ -119,7 +121,8 @@ fun isCustomTag(file: PsiFile, tag: XmlTag): Boolean {
|
||||
return isHtmlLikeFile(file) && !isHtmlTagName(descriptor, tag)
|
||||
}
|
||||
|
||||
private fun isHtmlLikeFile(file: PsiFile) = file.viewProvider.allFiles.any { it is HtmlCompatibleFile } || HtmlUtil.supportsXmlTypedHandlers(file)
|
||||
private fun isHtmlLikeFile(file: PsiFile) = file.viewProvider.allFiles.any { it is HtmlCompatibleFile } || HtmlUtil.supportsXmlTypedHandlers(
|
||||
file)
|
||||
|
||||
private fun isHtmlTagName(descriptor: XmlElementDescriptor, tag: XmlTag): Boolean {
|
||||
if (descriptor is HtmlElementDescriptorImpl) return true
|
||||
|
||||
Reference in New Issue
Block a user