Browse Source
Merge pull request #1318 from jkoritzinsky/fixes/424-selectionstart
Move CaretIndex to SelectionStart/End when SelectionStart equals SelectionEnd
pull/1323/head
Jeremy Koritzinsky
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
24 additions and
0 deletions
-
src/Avalonia.Controls/TextBox.cs
-
tests/Avalonia.Controls.UnitTests/TextBoxTests.cs
|
|
|
@ -178,6 +178,10 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
value = CoerceCaretIndex(value); |
|
|
|
SetAndRaise(SelectionStartProperty, ref _selectionStart, value); |
|
|
|
if (SelectionStart == SelectionEnd) |
|
|
|
{ |
|
|
|
CaretIndex = SelectionStart; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -192,6 +196,10 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
value = CoerceCaretIndex(value); |
|
|
|
SetAndRaise(SelectionEndProperty, ref _selectionEnd, value); |
|
|
|
if (SelectionStart == SelectionEnd) |
|
|
|
{ |
|
|
|
CaretIndex = SelectionEnd; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -202,6 +202,22 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Setting_SelectionStart_To_SelectionEnd_Sets_CaretPosition_To_SelectionStart() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(Services)) |
|
|
|
{ |
|
|
|
var textBox = new TextBox |
|
|
|
{ |
|
|
|
Text = "0123456789" |
|
|
|
}; |
|
|
|
|
|
|
|
textBox.SelectionStart = 2; |
|
|
|
textBox.SelectionEnd = 2; |
|
|
|
Assert.Equal(2, textBox.CaretIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Setting_Text_Updates_CaretPosition() |
|
|
|
{ |
|
|
|
|