Browse Source

XmlParser now handles equals sign inside quotes when checking if cursor is inside an attribute value.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4139 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts^2
Matt Ward 16 years ago
parent
commit
4e32c63398
  1. 1
      src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/XmlTests.cs
  2. 23
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlParser.cs
  3. 8
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeValueUnderCursorTests.cs

1
src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/XmlTests.cs

@ -69,7 +69,6 @@ namespace ICSharpCode.XamlBinding.Tests @@ -69,7 +69,6 @@ namespace ICSharpCode.XamlBinding.Tests
}
[Test]
[Ignore("Failing Test broke the build for 3 days - ignoring it. Reenable this test when the XmlParser bug is fixed!")]
public void InMarkupExtensionNamedParameterTest()
{
string xaml = "<Test val1=\"{Binding Value, Path=Control}\" />";

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

@ -323,16 +323,12 @@ namespace ICSharpCode.XmlEditor @@ -323,16 +323,12 @@ namespace ICSharpCode.XmlEditor
// Count the number of double quotes and single quotes that exist
// before the first equals sign encountered going backwards to
// the start of the active element.
bool foundEqualsSign = false;
int doubleQuotesCount = 0;
int singleQuotesCount = 0;
char lastQuoteChar = ' ';
for (int i = index - 1; i > elementStartIndex; --i) {
char ch = xml[i];
if (ch == '=') {
foundEqualsSign = true;
break;
} else if (ch == '\"') {
if (ch == '\"') {
lastQuoteChar = ch;
++doubleQuotesCount;
} else if (ch == '\'') {
@ -341,18 +337,13 @@ namespace ICSharpCode.XmlEditor @@ -341,18 +337,13 @@ namespace ICSharpCode.XmlEditor
}
}
bool isInside = false;
if (foundEqualsSign) {
// Odd number of quotes?
if ((lastQuoteChar == '\"') && ((doubleQuotesCount % 2) > 0)) {
isInside = true;
} else if ((lastQuoteChar == '\'') && ((singleQuotesCount %2) > 0)) {
isInside = true;
}
// Odd number of quotes?
if ((lastQuoteChar == '\"') && ((doubleQuotesCount % 2) > 0)) {
return true;
} else if ((lastQuoteChar == '\'') && ((singleQuotesCount %2) > 0)) {
return true;
}
return isInside;
return false;
}
/// <summary>

8
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeValueUnderCursorTests.cs

@ -79,6 +79,14 @@ namespace XmlEditor.Tests.Parser @@ -79,6 +79,14 @@ namespace XmlEditor.Tests.Parser
Assert.AreEqual("{Binding Value}", XmlParser.GetAttributeValueAtIndex(xaml, offset));
}
[Test]
public void InMarkupExtensionNamedParameterTest()
{
string xaml = "<Test val1=\"{Binding Value, Path=Control}\" />";
int offset = "<Test val1=\"{Binding Value, Path=".Length;
Assert.IsTrue(XmlParser.IsInsideAttributeValue(xaml, offset));
}
[Test]
public void LeftCurlyBracketIsValidAttributeValueChar()
{

Loading…
Cancel
Save