|
@@ -1535,6 +1535,172 @@ namespace Avalonia.Controls.UnitTests
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ [Theory]
|
|
|
+ [InlineData(2,4)]
|
|
|
+ [InlineData(0,4)]
|
|
|
+ [InlineData(2,6)]
|
|
|
+ [InlineData(0,6)]
|
|
|
+ public void When_Selection_From_Left_To_Right_Pressing_Right_Should_Remove_Selection_Moving_Caret_To_End_Of_Previous_Selection(int selectionStart, int selectionEnd)
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(Services))
|
|
|
+ {
|
|
|
+ var tb = new TextBox
|
|
|
+ {
|
|
|
+ Template = CreateTemplate(),
|
|
|
+ Text = "ABCDEF"
|
|
|
+ };
|
|
|
+
|
|
|
+ tb.Measure(Size.Infinity);
|
|
|
+ tb.CaretIndex = selectionStart;
|
|
|
+ tb.SelectionStart = selectionStart;
|
|
|
+ tb.SelectionEnd = selectionEnd;
|
|
|
+
|
|
|
+ RaiseKeyEvent(tb, Key.Right, KeyModifiers.None);
|
|
|
+
|
|
|
+ Assert.Equal(selectionEnd, tb.SelectionStart);
|
|
|
+ Assert.Equal(selectionEnd, tb.SelectionEnd);
|
|
|
+ Assert.Equal(selectionEnd, tb.CaretIndex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData(2,4)]
|
|
|
+ [InlineData(0,4)]
|
|
|
+ [InlineData(2,6)]
|
|
|
+ [InlineData(0,6)]
|
|
|
+ public void When_Selection_From_Left_To_Right_Pressing_Left_Should_Remove_Selection_Moving_Caret_To_Start_Of_Previous_Selection(int selectionStart, int selectionEnd)
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(Services))
|
|
|
+ {
|
|
|
+ var tb = new TextBox
|
|
|
+ {
|
|
|
+ Template = CreateTemplate(),
|
|
|
+ Text = "ABCDEF"
|
|
|
+ };
|
|
|
+
|
|
|
+ tb.Measure(Size.Infinity);
|
|
|
+ tb.CaretIndex = selectionStart;
|
|
|
+ tb.SelectionStart = selectionStart;
|
|
|
+ tb.SelectionEnd = selectionEnd;
|
|
|
+
|
|
|
+ RaiseKeyEvent(tb, Key.Left, KeyModifiers.None);
|
|
|
+
|
|
|
+ Assert.Equal(selectionStart, tb.SelectionStart);
|
|
|
+ Assert.Equal(selectionStart, tb.SelectionEnd);
|
|
|
+ Assert.Equal(selectionStart, tb.CaretIndex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData(4,2)]
|
|
|
+ [InlineData(4,0)]
|
|
|
+ [InlineData(6,2)]
|
|
|
+ [InlineData(6,0)]
|
|
|
+ public void When_Selection_From_Right_To_Left_Pressing_Right_Should_Remove_Selection_Moving_Caret_To_Start_Of_Previous_Selection(int selectionStart, int selectionEnd)
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(Services))
|
|
|
+ {
|
|
|
+ var tb = new TextBox
|
|
|
+ {
|
|
|
+ Template = CreateTemplate(),
|
|
|
+ Text = "ABCDEF"
|
|
|
+ };
|
|
|
+
|
|
|
+ tb.Measure(Size.Infinity);
|
|
|
+ tb.CaretIndex = selectionStart;
|
|
|
+ tb.SelectionStart = selectionStart;
|
|
|
+ tb.SelectionEnd = selectionEnd;
|
|
|
+
|
|
|
+ RaiseKeyEvent(tb, Key.Right, KeyModifiers.None);
|
|
|
+
|
|
|
+ Assert.Equal(selectionStart, tb.SelectionStart);
|
|
|
+ Assert.Equal(selectionStart, tb.SelectionEnd);
|
|
|
+ Assert.Equal(selectionStart, tb.CaretIndex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData(4,2)]
|
|
|
+ [InlineData(4,0)]
|
|
|
+ [InlineData(6,2)]
|
|
|
+ [InlineData(6,0)]
|
|
|
+ public void When_Selection_From_Right_To_Left_Pressing_Left_Should_Remove_Selection_Moving_Caret_To_End_Of_Previous_Selection(int selectionStart, int selectionEnd)
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(Services))
|
|
|
+ {
|
|
|
+ var tb = new TextBox
|
|
|
+ {
|
|
|
+ Template = CreateTemplate(),
|
|
|
+ Text = "ABCDEF"
|
|
|
+ };
|
|
|
+
|
|
|
+ tb.Measure(Size.Infinity);
|
|
|
+ tb.CaretIndex = selectionStart;
|
|
|
+ tb.SelectionStart = selectionStart;
|
|
|
+ tb.SelectionEnd = selectionEnd;
|
|
|
+
|
|
|
+ RaiseKeyEvent(tb, Key.Left, KeyModifiers.None);
|
|
|
+
|
|
|
+ Assert.Equal(selectionEnd, tb.SelectionStart);
|
|
|
+ Assert.Equal(selectionEnd, tb.SelectionEnd);
|
|
|
+ Assert.Equal(selectionEnd, tb.CaretIndex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData(0)]
|
|
|
+ [InlineData(2)]
|
|
|
+ [InlineData(4)]
|
|
|
+ [InlineData(6)]
|
|
|
+ public void When_Select_All_From_Position_Left_Should_Remove_Selection_Moving_Caret_To_Start(int caretIndex)
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(Services))
|
|
|
+ {
|
|
|
+ var tb = new TextBox
|
|
|
+ {
|
|
|
+ Template = CreateTemplate(),
|
|
|
+ Text = "ABCDEF"
|
|
|
+ };
|
|
|
+
|
|
|
+ tb.Measure(Size.Infinity);
|
|
|
+ tb.CaretIndex = caretIndex;
|
|
|
+
|
|
|
+ RaiseKeyEvent(tb, Key.A, KeyModifiers.Control);
|
|
|
+ RaiseKeyEvent(tb, Key.Left, KeyModifiers.None);
|
|
|
+
|
|
|
+ Assert.Equal(0, tb.SelectionStart);
|
|
|
+ Assert.Equal(0, tb.SelectionEnd);
|
|
|
+ Assert.Equal(0, tb.CaretIndex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData(0)]
|
|
|
+ [InlineData(2)]
|
|
|
+ [InlineData(4)]
|
|
|
+ [InlineData(6)]
|
|
|
+ public void When_Select_All_From_Position_Right_Should_Remove_Selection_Moving_Caret_To_End(int caretIndex)
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(Services))
|
|
|
+ {
|
|
|
+ var tb = new TextBox
|
|
|
+ {
|
|
|
+ Template = CreateTemplate(),
|
|
|
+ Text = "ABCDEF"
|
|
|
+ };
|
|
|
+
|
|
|
+ tb.Measure(Size.Infinity);
|
|
|
+ tb.CaretIndex = caretIndex;
|
|
|
+
|
|
|
+ RaiseKeyEvent(tb, Key.A, KeyModifiers.Control);
|
|
|
+ RaiseKeyEvent(tb, Key.Right, KeyModifiers.None);
|
|
|
+
|
|
|
+ Assert.Equal(tb.Text.Length, tb.SelectionStart);
|
|
|
+ Assert.Equal(tb.Text.Length, tb.SelectionEnd);
|
|
|
+ Assert.Equal(tb.Text.Length, tb.CaretIndex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
[Fact]
|
|
|
public void TextBox_In_AdornerLayer_Will_Not_Cause_Collection_Modified_In_VisualLayerManager_Measure()
|
|
|
{
|