From 4c30232db3a552a3898db50293ca0ec0be5a0010 Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Thu, 19 Nov 2015 10:35:42 +0000 Subject: [PATCH] fix sync editing going crazy with a second colon in a tag name --- .../codeInsight/editorActions/XmlTagNameSynchronizer.java | 5 ++++- .../codeInsight/completion/XmlSyncTagCommunityTest.java | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/xml/impl/src/com/intellij/codeInsight/editorActions/XmlTagNameSynchronizer.java b/xml/impl/src/com/intellij/codeInsight/editorActions/XmlTagNameSynchronizer.java index 0795a7e50632..0e47bf62c051 100644 --- a/xml/impl/src/com/intellij/codeInsight/editorActions/XmlTagNameSynchronizer.java +++ b/xml/impl/src/com/intellij/codeInsight/editorActions/XmlTagNameSynchronizer.java @@ -262,6 +262,7 @@ public class XmlTagNameSynchronizer extends CommandAdapter implements NamedCompo final CharSequence sequence = document.getCharsSequence(); int start = -1; int end = -1; + boolean seenColon = false; for (int i = offset - 1; i >= Math.max(0, offset - 50); i--) { try { final char c = sequence.charAt(i); @@ -270,6 +271,7 @@ public class XmlTagNameSynchronizer extends CommandAdapter implements NamedCompo break; } if (!XmlUtil.isValidTagNameChar(c)) break; + seenColon |= c == ':'; } catch (IndexOutOfBoundsException e) { LOG.error("incorrect offset:" + i + ", initial: " + offset, new Attachment("document.txt", sequence.toString())); @@ -279,10 +281,11 @@ public class XmlTagNameSynchronizer extends CommandAdapter implements NamedCompo if (start < 0) return null; for (int i = offset; i < Math.min(document.getTextLength(), offset + 50); i++) { final char c = sequence.charAt(i); - if (!XmlUtil.isValidTagNameChar(c)) { + if (!XmlUtil.isValidTagNameChar(c) || (seenColon && c == ':')) { end = i; break; } + seenColon |= c == ':'; } if (end < 0 || start >= end) return null; return document.createRangeMarker(start, end, true); diff --git a/xml/tests/src/com/intellij/codeInsight/completion/XmlSyncTagCommunityTest.java b/xml/tests/src/com/intellij/codeInsight/completion/XmlSyncTagCommunityTest.java index 645cc90525b8..f97cdce98558 100644 --- a/xml/tests/src/com/intellij/codeInsight/completion/XmlSyncTagCommunityTest.java +++ b/xml/tests/src/com/intellij/codeInsight/completion/XmlSyncTagCommunityTest.java @@ -155,6 +155,10 @@ public class XmlSyncTagCommunityTest extends XmlSyncTagTest { doTest("
", "\b\b\b\b\b\b", "
"); } + public void testDoubleColonError() { + doTest(":some>", "a", ""); + } + public void testMultipleEditors() { myFixture.configureByText(XmlFileType.INSTANCE, ">"); final Editor editor = EditorFactory.getInstance().createEditor(myFixture.getEditor().getDocument());