Skip to content

Commit

Permalink
Autoclose tag generates an unexpected >
Browse files Browse the repository at this point in the history
Fixes #1221

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Nov 25, 2022
1 parent c26c2df commit 8bf597b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@
class XMLLinkedEditing {

private static Logger LOGGER = Logger.getLogger(XMLLinkedEditing.class.getName());

// Full XML Element name pattern
public static final String XML_ELEMENT_WORD_PATTERN =
"[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6" //$NON-NLS-1$
+ "\\u00F8-\\u02ff\\u0370-\\u037d\\u037f-\\u1fff\\u200c\\u200d\\u2070-\\u218f" //$NON-NLS-1$
+ "\\u2c00-\\u2fef\\u3001-\\udfff\\uf900-\\ufdcf\\ufdf0-\\ufffd\\u10000-\\uEFFFF]" //$NON-NLS-1$
+ "[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6" //$NON-NLS-1$
+ "\\u00F8-\\u02ff\\u0370-\\u037d\\u037f-\\u1fff\\u200c\\u200d\\u2070-\\u218f" //$NON-NLS-1$
+ "\\u2c00-\\u2fef\\u3001-\\udfff\\uf900-\\ufdcf\\ufdf0-\\ufffd\\u10000-\\uEFFFF\\-\\.0-9" //$NON-NLS-1$
+ "\\u00b7\\u0300-\\u036f\\u203f-\\u2040]*"; //$NON-NLS-1$

/**
* Returns the linked editing ranges for the given <code>xmlDocument</code> at
Expand Down Expand Up @@ -75,7 +65,7 @@ public LinkedEditingRanges findLinkedEditingRanges(DOMDocument document, Positio

cancelChecker.checkCanceled();

return new LinkedEditingRanges(ranges, XML_ELEMENT_WORD_PATTERN);
return new LinkedEditingRanges(ranges);
}
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "In XMLLinkedEditing, position error", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static org.eclipse.lemminx.XMLAssert.le;
import static org.eclipse.lemminx.XMLAssert.r;
import static org.eclipse.lemminx.XMLAssert.testLinkedEditingFor;
import static org.eclipse.lemminx.services.XMLLinkedEditing.XML_ELEMENT_WORD_PATTERN;

import org.eclipse.lemminx.commons.BadLocationException;
import org.junit.jupiter.api.Test;

Expand All @@ -36,24 +36,24 @@ public void linkedEditingWithOrpheanEndTag() throws BadLocationException {
@Test
public void linkedEditing() throws BadLocationException {
testLinkedEditingFor("|<div></div>", null);
testLinkedEditingFor("<|div></div>", le(XML_ELEMENT_WORD_PATTERN,r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<d|iv></div>", le(XML_ELEMENT_WORD_PATTERN,r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<di|v></div>", le(XML_ELEMENT_WORD_PATTERN,r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<div|></div>", le(XML_ELEMENT_WORD_PATTERN,r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<|div></div>", le(r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<d|iv></div>", le(r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<di|v></div>", le(r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<div|></div>", le(r(0, 1, 0, 4), r(0, 7, 0, 10)));

testLinkedEditingFor("<div>|</div>", null);
testLinkedEditingFor("<div><|/div>", null);

testLinkedEditingFor("<div></|div>", le(XML_ELEMENT_WORD_PATTERN,r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<div></d|iv>", le(XML_ELEMENT_WORD_PATTERN,r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<div></di|v>", le(XML_ELEMENT_WORD_PATTERN,r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<div></div|>", le(XML_ELEMENT_WORD_PATTERN,r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<div></|div>", le(r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<div></d|iv>", le(r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<div></di|v>", le(r(0, 1, 0, 4), r(0, 7, 0, 10)));
testLinkedEditingFor("<div></div|>", le(r(0, 1, 0, 4), r(0, 7, 0, 10)));

testLinkedEditingFor("<div></div>|", null);
testLinkedEditingFor("<div><div|</div>", le(XML_ELEMENT_WORD_PATTERN,r(0, 6, 0, 9), r(0, 11, 0, 14)));
testLinkedEditingFor("<div><div><div|</div></div>", le(XML_ELEMENT_WORD_PATTERN,r(0, 11, 0, 14), r(0, 16, 0, 19)));
testLinkedEditingFor("<div><div|</div>", le(r(0, 6, 0, 9), r(0, 11, 0, 14)));
testLinkedEditingFor("<div><div><div|</div></div>", le(r(0, 11, 0, 14), r(0, 16, 0, 19)));

testLinkedEditingFor("<div| ></div>", le(XML_ELEMENT_WORD_PATTERN,r(0, 1, 0, 4), r(0, 8, 0, 11)));
testLinkedEditingFor("<div| id='foo'></div>", le(XML_ELEMENT_WORD_PATTERN,r(0, 1, 0, 4), r(0, 16, 0, 19)));
testLinkedEditingFor("<div| ></div>", le(r(0, 1, 0, 4), r(0, 8, 0, 11)));
testLinkedEditingFor("<div| id='foo'></div>", le(r(0, 1, 0, 4), r(0, 16, 0, 19)));
}
}

0 comments on commit 8bf597b

Please sign in to comment.