diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionWindow.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionWindow.cs
index c960494dde..edf94c2d9c 100644
--- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionWindow.cs
+++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionWindow.cs
@@ -82,6 +82,11 @@ namespace ICSharpCode.XmlEditor
declarationViewWindow.ShowDeclarationViewWindow();
control.Focus();
CodeCompletionListViewSelectedItemChanged(this, EventArgs.Empty);
+
+ if (completionDataProvider.DefaultIndex >= 0) {
+ codeCompletionListView.SelectIndex(completionDataProvider.DefaultIndex);
+ }
+
if (completionDataProvider.PreSelection != null) {
CaretOffsetChanged(this, EventArgs.Empty);
}
diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCompletionDataProvider.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCompletionDataProvider.cs
index cd18c07023..4824c3cc5b 100644
--- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCompletionDataProvider.cs
+++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCompletionDataProvider.cs
@@ -28,6 +28,7 @@ namespace ICSharpCode.XmlEditor
this.schemaCompletionDataItems = schemaCompletionDataItems;
this.defaultSchemaCompletionData = defaultSchemaCompletionData;
this.defaultNamespacePrefix = defaultNamespacePrefix;
+ DefaultIndex = 0;
}
public override ImageList ImageList {
diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Completion/FirstCompletionListItemSelectedTestFixture.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Completion/FirstCompletionListItemSelectedTestFixture.cs
new file mode 100644
index 0000000000..503284d118
--- /dev/null
+++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Completion/FirstCompletionListItemSelectedTestFixture.cs
@@ -0,0 +1,92 @@
+//
+//
+//
+//
+// $Revision$
+//
+
+using System;
+using System.Collections.Generic;
+using System.Windows.Forms;
+using ICSharpCode.TextEditor;
+using ICSharpCode.TextEditor.Gui.CompletionWindow;
+using ICSharpCode.XmlEditor;
+using NUnit.Framework;
+using XmlEditor.Tests.Utils;
+
+namespace XmlEditor.Tests.Completion
+{
+ ///
+ /// Tests that the first item in the completion list view is selected by
+ /// default. When coding in C# the default is to not selected the
+ /// first item in the completion list. With XML there tends to not
+ /// be very many items in the completion list so selecting the first
+ /// one can often make editing quicker.
+ ///
+ [TestFixture]
+ public class FirstCompletionListItemSelectedTestFixture
+ {
+ XmlCompletionDataProvider provider;
+ ICompletionData selectedCompletionData;
+ ICompletionData[] completionDataItems;
+
+ [TestFixtureSetUp]
+ public void SetUpFixture()
+ {
+ Form parentForm = new Form();
+ parentForm.CreateControl();
+
+ XmlSchemaCompletionData schema = new XmlSchemaCompletionData(ResourceManager.GetXhtmlStrictSchema());
+ XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();
+ schemas.Add(schema);
+ provider = new XmlCompletionDataProvider(schemas, schema, String.Empty);
+ TextEditorControl textEditor = new TextEditorControl();
+ completionDataItems = provider.GenerateCompletionData(@"C:\Test.xml", textEditor.ActiveTextAreaControl.TextArea, '<');
+ using (ICSharpCode.XmlEditor.CodeCompletionWindow completionWindow = ICSharpCode.XmlEditor.CodeCompletionWindow.ShowCompletionWindow(parentForm, textEditor, @"C:\Test.xml", provider, '<')) {
+ CodeCompletionListView listView = (CodeCompletionListView)completionWindow.Controls[0];
+ selectedCompletionData = listView.SelectedCompletionData;
+ completionWindow.Close();
+ }
+ }
+
+ ///
+ /// Sanity check to make sure that we actually have some completion
+ /// data items from the xml completion data provider.
+ ///
+ [Test]
+ public void HasGeneratedCompletionDataItems()
+ {
+ Assert.IsNotNull(completionDataItems);
+ Assert.IsTrue(completionDataItems.Length > 0);
+ }
+
+ ///
+ /// Default index should be zero so that the first item in the
+ /// list view is selected.
+ ///
+ [Test]
+ public void DefaultIndex()
+ {
+ Assert.AreEqual(0, provider.DefaultIndex);
+ }
+
+ [Test]
+ public void SelectedCompletionDataExists()
+ {
+ Assert.IsNotNull(selectedCompletionData);
+ }
+
+ ///
+ /// First item returned from completion list view should correspond
+ /// to the first completion item returned from the xml completion
+ /// data provider after those items have been sorted.
+ ///
+ [Test]
+ public void SelectedCompletionDataMatches()
+ {
+ List items = new List(completionDataItems);
+ items.Sort();
+ Assert.AreEqual(items[0].Text, selectedCompletionData.Text);
+ }
+ }
+}
diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj b/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj
index ee92afec0a..d61ef1c807 100644
--- a/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj
+++ b/src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj
@@ -44,6 +44,7 @@
+
@@ -164,6 +165,7 @@
+