Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix XML code completion inside a child element when default schema as…

…sociated by filename extension is being used.
  • Loading branch information...
commit 5165582dded1463408882765ed47d9f355e16166 1 parent 5de1b35
@mrward mrward authored
View
12 src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionCollection.cs
@@ -124,10 +124,10 @@ XmlSchemaCompletionCollection GetSchemaCollectionUsingDefaultSchema(XmlElementPa
return schemas;
}
- public XmlCompletionItemCollection GetChildElementCompletion(XmlElementPath path)
+ public XmlCompletionItemCollection GetChildElementCompletion(XmlElementPath path, XmlSchemaCompletion defaultSchema)
{
XmlCompletionItemCollection items = new XmlCompletionItemCollection();
- foreach (XmlSchemaCompletion schema in GetSchemas(path, null)) {
+ foreach (XmlSchemaCompletion schema in GetSchemas(path, defaultSchema)) {
items.AddRange(schema.GetChildElementCompletion(path));
}
return items;
@@ -143,12 +143,14 @@ public XmlCompletionItemCollection GetElementCompletion(XmlElementPathsByNamespa
{
XmlCompletionItemCollection items = new XmlCompletionItemCollection();
foreach (XmlElementPath path in pathsByNamespace) {
- items.AddRange(GetChildElementCompletion(path));
+ items.AddRange(GetChildElementCompletion(path, defaultSchema));
}
XmlNamespaceCollection namespaceWithoutPaths = pathsByNamespace.NamespacesWithoutPaths;
- if (!IsDefaultSchemaNamespaceDefinedInPathsByNamespace(namespaceWithoutPaths, defaultSchema)) {
- namespaceWithoutPaths.Add(defaultSchema.Namespace);
+ if (items.Count == 0) {
+ if (!IsDefaultSchemaNamespaceDefinedInPathsByNamespace(namespaceWithoutPaths, defaultSchema)) {
+ namespaceWithoutPaths.Add(defaultSchema.Namespace);
+ }
}
items.AddRange(GetRootElementCompletion(namespaceWithoutPaths));
return items;
View
30 .../Completion/ElementCompletionWindowTestFixture.cs → ...r/Test/Completion/ElementCompletionWindowTests.cs
@@ -13,11 +13,12 @@
namespace XmlEditor.Tests.Completion
{
[TestFixture]
- public class ElementCompletionWindowTestFixture
+ public class ElementCompletionWindowTests
{
MockTextEditor textEditor;
CodeCompletionKeyPressResult keyPressResult;
XmlSchemaCompletionCollection schemas;
+ XmlCodeCompletionBinding completionBinding;
[SetUp]
public void Init()
@@ -34,20 +35,37 @@ public void Init()
textEditor.Caret.Offset = 0;
- XmlCodeCompletionBinding completionBinding = new XmlCodeCompletionBinding(associations);
- keyPressResult = completionBinding.HandleKeyPress(textEditor, '<');
+ completionBinding = new XmlCodeCompletionBinding(associations);
}
[Test]
- public void KeyPressResultIsCompletedAfterPressingEqualsSign()
+ public void HandleKeyPress_LessThanKeyPressed_KeyPressResultIsCompletedAfterPressingLessThanSign()
{
+ keyPressResult = completionBinding.HandleKeyPress(textEditor, '<');
Assert.AreEqual(CodeCompletionKeyPressResult.Completed, keyPressResult);
}
[Test]
- public void CompletionWindowWidthIsNotSetToMatchLongestNamespaceTextWidth()
+ public void HandleKeyPress_LessThanKeyPressed_CompletionWindowWidthIsNotSetToMatchLongestNamespaceTextWidth()
{
+ completionBinding.HandleKeyPress(textEditor, '<');
Assert.AreNotEqual(double.NaN, textEditor.CompletionWindowDisplayed.Width);
- }
+ }
+
+ [Test]
+ public void HandleKeyPress_LessThanKeyPressedInsideRootHtmlElement_BodyElementExistsInChildCompletionItems()
+ {
+ textEditor.Document.Text =
+ "<html><\r\n" +
+ "</html>";
+ textEditor.Caret.Offset = 6;
+
+ completionBinding.HandleKeyPress(textEditor, '<');
+ ICompletionItem[] items = textEditor.CompletionItemsDisplayedToArray();
+
+ XmlCompletionItem expectedItem = new XmlCompletionItem("body", XmlCompletionItemType.XmlElement);
+
+ Assert.Contains(expectedItem, items);
+ }
}
}
View
2  ...s/DisplayBindings/XmlEditor/Test/Schema.Multiple/DuplicateSchemaNamespaceAddedToCollectionTestFixture.cs
@@ -240,7 +240,7 @@ public void GetChildElementCompletionForDuplicateFooRootElement()
{
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("duplicate-foo-note", "foo"));
- XmlCompletionItemCollection items = schemas.GetChildElementCompletion(path);
+ XmlCompletionItemCollection items = schemas.GetChildElementCompletion(path, null);
items.Sort();
List<XmlCompletionItem> expectedItems = new List<XmlCompletionItem>();
View
2  src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj
@@ -80,7 +80,7 @@
<Compile Include="Completion\CompleteCompletionItemListTestFixture.cs" />
<Compile Include="Completion\CtrlSpaceAttributeValueCompletionTestFixture.cs" />
<Compile Include="Completion\CtrlSpaceNoAttributeValuesForCompletionTestFixture.cs" />
- <Compile Include="Completion\ElementCompletionWindowTestFixture.cs" />
+ <Compile Include="Completion\ElementCompletionWindowTests.cs" />
<Compile Include="Completion\FirstCompletionListItemSelectedTestFixture.cs" />
<Compile Include="Completion\NamespaceCompletionWindowTestFixture.cs" />
<Compile Include="Completion\NamespaceCompletionWindowTestFixtureBase.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.