浏览代码

Merge branch 'master' into bench-style-attach

Dariusz Komosiński 5 年之前
父节点
当前提交
cebf6f20bc
共有 3 个文件被更改,包括 58 次插入6 次删除
  1. 6 5
      src/Avalonia.Controls/TextBox.cs
  2. 1 1
      src/Avalonia.Controls/Window.cs
  3. 51 0
      tests/Avalonia.Controls.UnitTests/WindowTests.cs

+ 6 - 5
src/Avalonia.Controls/TextBox.cs

@@ -316,8 +316,7 @@ namespace Avalonia.Controls
                 !AcceptsReturn &&
                 !AcceptsReturn &&
                 Text?.Length > 0)
                 Text?.Length > 0)
             {
             {
-                SelectionStart = 0;
-                SelectionEnd = Text.Length;
+                SelectAll();
             }
             }
             else
             else
             {
             {
@@ -673,8 +672,7 @@ namespace Avalonia.Controls
                         SelectionEnd = StringUtils.NextWord(text, index);
                         SelectionEnd = StringUtils.NextWord(text, index);
                         break;
                         break;
                     case 3:
                     case 3:
-                        SelectionStart = 0;
-                        SelectionEnd = text.Length;
+                        SelectAll();
                         break;
                         break;
                 }
                 }
             }
             }
@@ -896,7 +894,10 @@ namespace Avalonia.Controls
             CaretIndex = caretIndex;
             CaretIndex = caretIndex;
         }
         }
 
 
-        private void SelectAll()
+        /// <summary>
+        /// Select all text in the TextBox
+        /// </summary>
+        public void SelectAll()
         {
         {
             SelectionStart = 0;
             SelectionStart = 0;
             SelectionEnd = Text?.Length ?? 0;
             SelectionEnd = Text?.Length ?? 0;

+ 1 - 1
src/Avalonia.Controls/Window.cs

@@ -529,7 +529,7 @@ namespace Avalonia.Controls
         {
         {
             var sizeToContent = SizeToContent;
             var sizeToContent = SizeToContent;
             var clientSize = ClientSize;
             var clientSize = ClientSize;
-            Size constraint = clientSize;
+            var constraint = availableSize;
 
 
             if ((sizeToContent & SizeToContent.Width) != 0)
             if ((sizeToContent & SizeToContent.Width) != 0)
             {
             {

+ 51 - 0
tests/Avalonia.Controls.UnitTests/WindowTests.cs

@@ -341,11 +341,62 @@ namespace Avalonia.Controls.UnitTests
             }
             }
         }
         }
 
 
+        [Fact]
+        public void Child_Should_Be_Measured_With_Width_And_Height_If_SizeToContent_Is_Manual()
+        {
+            using (UnitTestApplication.Start(TestServices.StyledWindow))
+            {
+                var child = new ChildControl();
+                var target = new Window 
+                { 
+                    Width = 100,
+                    Height = 50,
+                    SizeToContent = SizeToContent.Manual,
+                    Content = child 
+                };
+
+                target.Show();
+
+                Assert.Equal(new Size(100, 50), child.MeasureSize);
+            }
+        }
+
+        [Fact]
+        public void Child_Should_Be_Measured_With_Infinity_If_SizeToContent_Is_WidthAndHeight()
+        {
+            using (UnitTestApplication.Start(TestServices.StyledWindow))
+            {
+                var child = new ChildControl();
+                var target = new Window
+                {
+                    Width = 100,
+                    Height = 50,
+                    SizeToContent = SizeToContent.WidthAndHeight,
+                    Content = child
+                };
+
+                target.Show();
+
+                Assert.Equal(Size.Infinity, child.MeasureSize);
+            }
+        }
+
         private IWindowImpl CreateImpl(Mock<IRenderer> renderer)
         private IWindowImpl CreateImpl(Mock<IRenderer> renderer)
         {
         {
             return Mock.Of<IWindowImpl>(x =>
             return Mock.Of<IWindowImpl>(x =>
                 x.Scaling == 1 &&
                 x.Scaling == 1 &&
                 x.CreateRenderer(It.IsAny<IRenderRoot>()) == renderer.Object);
                 x.CreateRenderer(It.IsAny<IRenderRoot>()) == renderer.Object);
         }
         }
+
+        private class ChildControl : Control
+        {
+            public Size MeasureSize { get; private set; }
+
+            protected override Size MeasureOverride(Size availableSize)
+            {
+                MeasureSize = availableSize;
+                return base.MeasureOverride(availableSize);
+            }
+        }
     }
     }
 }
 }