Browse Source

XmlParser now returning the correct active element if the element is followed by a tab or new line character.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3938 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
80aa8f7476
  1. 4
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs
  2. 27
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/ActiveElementUnderCursorTests.cs

4
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs

@ -68,6 +68,8 @@ namespace ICSharpCode.XmlEditor @@ -68,6 +68,8 @@ namespace ICSharpCode.XmlEditor
return namespaceURI;
}
}
static readonly char[] whitespaceCharacters = new char[] {' ', '\n', '\t', '\r'};
XmlParser()
{
@ -662,7 +664,7 @@ namespace ICSharpCode.XmlEditor @@ -662,7 +664,7 @@ namespace ICSharpCode.XmlEditor
if (elementStartIndex >= 0 && elementStartIndex < index) {
int elementEndIndex = GetActiveElementEndIndex(xml, index);
if (elementEndIndex == -1) {
elementEndIndex = xml.IndexOf(' ', elementStartIndex);
elementEndIndex = xml.IndexOfAny(whitespaceCharacters, elementStartIndex);
}
if (elementEndIndex >= elementStartIndex) {
return xml.Substring(elementStartIndex, elementEndIndex - elementStartIndex);

27
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/ActiveElementUnderCursorTests.cs

@ -175,5 +175,32 @@ namespace XmlEditor.Tests.Parser @@ -175,5 +175,32 @@ namespace XmlEditor.Tests.Parser
"Incorrect active element path.");
}
[Test]
public void PathWithNewLine()
{
string text = "<foo xmlns='" + namespaceURI + "'><bar";
string text2 = "\n</foo>";
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text + text2, text.Length);
expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), "Incorrect active element path.");
}
[Test]
public void PathWithTab()
{
string text = "<foo xmlns='" + namespaceURI + "'><bar";
string text2 = "\t</foo>";
elementPath = XmlParser.GetActiveElementStartPathAtIndex(text + text2, text.Length);
expectedElementPath = new XmlElementPath();
expectedElementPath.Elements.Add(new QualifiedName("foo", namespaceURI));
expectedElementPath.Elements.Add(new QualifiedName("bar", namespaceURI));
Assert.IsTrue(elementPath.Equals(expectedElementPath), "Incorrect active element path.");
}
}
}

Loading…
Cancel
Save