Explorar o código

Merge branch 'master' into patch-3

Jeremy Koritzinsky %!s(int64=8) %!d(string=hai) anos
pai
achega
a5bf341fe5

+ 1 - 1
src/Avalonia.Base/Collections/AvaloniaList.cs

@@ -220,7 +220,7 @@ namespace Avalonia.Collections
         /// <summary>
         /// Removes all items from the collection.
         /// </summary>
-        public void Clear()
+        public virtual void Clear()
         {
             if (this.Count > 0)
             {

+ 14 - 0
src/Avalonia.Controls/Classes.cs

@@ -86,6 +86,20 @@ namespace Avalonia.Controls
             base.AddRange(c);
         }
 
+        /// <summary>
+        /// Remvoes all non-pseudoclasses from the collection.
+        /// </summary>
+        public override void Clear()
+        {
+            for (var i = Count - 1; i >= 0; --i)
+            {
+                if (!this[i].StartsWith(":"))
+                {
+                    RemoveAt(i);
+                }
+            }
+        }
+
         /// <summary>
         /// Inserts a style class into the collection.
         /// </summary>

+ 12 - 0
tests/Avalonia.Controls.UnitTests/ClassesTests.cs

@@ -149,5 +149,17 @@ namespace Avalonia.Controls.UnitTests
 
             Assert.Throws<ArgumentException>(() => target.Replace(new[] { ":qux" }));
         }
+
+        [Fact]
+        public void Clear_Should_Not_Remove_Pseudoclasses()
+        {
+            var target = new Classes("foo", "bar");
+
+            ((IPseudoClasses)target).Add(":baz");
+
+            target.Clear();
+
+            Assert.Equal(new[] { ":baz" }, target);
+        }
     }
 }