fix sync editing going crazy with a second colon in a tag name

This commit is contained in:
Dennis Ushakov
2015-11-19 10:38:27 +00:00
parent b4228934d5
commit 4c30232db3
2 changed files with 8 additions and 1 deletions
@@ -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);
@@ -155,6 +155,10 @@ public class XmlSyncTagCommunityTest extends XmlSyncTagTest {
doTest("<div></div><caret></div>", "\b\b\b\b\b\b", "<div></div>");
}
public void testDoubleColonError() {
doTest("<soap:some<caret>:some></soap:some:some>", "a", "<soap:somea:some></soap:somea:some>");
}
public void testMultipleEditors() {
myFixture.configureByText(XmlFileType.INSTANCE, "<div<caret>></div>");
final Editor editor = EditorFactory.getInstance().createEditor(myFixture.getEditor().getDocument());