diff --git a/xml/impl/src/com/intellij/codeInsight/editorActions/XmlSlashTypedHandler.java b/xml/impl/src/com/intellij/codeInsight/editorActions/XmlSlashTypedHandler.java index 3a7ab2a3e0e2..c259054e8ab8 100644 --- a/xml/impl/src/com/intellij/codeInsight/editorActions/XmlSlashTypedHandler.java +++ b/xml/impl/src/com/intellij/codeInsight/editorActions/XmlSlashTypedHandler.java @@ -22,6 +22,7 @@ import com.intellij.openapi.editor.EditorModificationUtil; import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; @@ -34,7 +35,7 @@ import com.intellij.psi.xml.*; import com.intellij.xml.util.XmlUtil; import org.jetbrains.annotations.NotNull; -public class XmlSlashTypedHandler extends TypedHandlerDelegate { +public class XmlSlashTypedHandler extends TypedHandlerDelegate implements XmlTokenType { public Result beforeCharTyped(final char c, final Project project, final Editor editor, final PsiFile editedFile, final FileType fileType) { if ((editedFile.getLanguage() instanceof XMLLanguage || editedFile.getViewProvider().getBaseLanguage() instanceof XMLLanguage) && c == '/') { PsiDocumentManager.getInstance(project).commitAllDocuments(); @@ -80,10 +81,17 @@ public class XmlSlashTypedHandler extends TypedHandlerDelegate { if (!(element.getLanguage() instanceof XMLLanguage)) return Result.CONTINUE; ASTNode prevLeaf = element.getNode(); - final String prevLeafText = prevLeaf != null ? prevLeaf.getText():null; - if (prevLeaf != null && !"/".equals(prevLeafText)) { - if (!"/".equals(prevLeafText.trim())) return Result.CONTINUE; + if (prevLeaf == null) return Result.CONTINUE; + final String prevLeafText = prevLeaf.getText(); + if (""); + return Result.STOP; + } } + if (!"/".equals(prevLeafText.trim())) return Result.CONTINUE; + while((prevLeaf = TreeUtil.prevLeaf(prevLeaf)) != null && prevLeaf.getElementType() == XmlTokenType.XML_WHITE_SPACE); if(prevLeaf instanceof OuterLanguageElement) { element = file.getViewProvider().findElementAt(offset - 1, file.getLanguage()); diff --git a/xml/tests/src/com/intellij/codeInsight/completion/XmlTypedHandlersTest.java b/xml/tests/src/com/intellij/codeInsight/completion/XmlTypedHandlersTest.java new file mode 100644 index 000000000000..6a5edda198d8 --- /dev/null +++ b/xml/tests/src/com/intellij/codeInsight/completion/XmlTypedHandlersTest.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.completion; + +import com.intellij.ide.highlighter.XmlFileType; +import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; + +/** + * @author Dmitry Avdeev + * Date: 30.08.13 + */ +public class XmlTypedHandlersTest extends LightPlatformCodeInsightFixtureTestCase { + + public void testClosingTag() throws Exception { + myFixture.configureByText(XmlFileType.INSTANCE, "<"); + myFixture.type('/'); + myFixture.checkResult(""); + } +}