Browse Source

SelectedText = null -> clear text

pull/3748/head
Deadpikle 7 years ago
parent
commit
681911098c
  1. 11
      src/Avalonia.Controls/TextBox.cs
  2. 18
      tests/Avalonia.Controls.UnitTests/TextBoxTests.cs

11
src/Avalonia.Controls/TextBox.cs

@ -277,19 +277,14 @@ namespace Avalonia.Controls
get { return GetSelection(); } get { return GetSelection(); }
set set
{ {
if (value == null)
{
return;
}
_undoRedoHelper.Snapshot(); _undoRedoHelper.Snapshot();
if (value != "") if (string.IsNullOrEmpty(value))
{ {
HandleTextInput(value); DeleteSelection();
} }
else else
{ {
DeleteSelection(); HandleTextInput(value);
} }
_undoRedoHelper.Snapshot(); _undoRedoHelper.Snapshot();
} }

18
tests/Avalonia.Controls.UnitTests/TextBoxTests.cs

@ -443,6 +443,24 @@ namespace Avalonia.Controls.UnitTests
} }
} }
[Fact]
public void SelectedText_NullClearsText()
{
using (UnitTestApplication.Start(Services))
{
var target = new TextBox
{
Template = CreateTemplate(),
Text = "0123"
};
target.SelectionStart = 1;
target.SelectionEnd = 3;
target.SelectedText = null;
Assert.True(target.Text == "03");
}
}
[Fact] [Fact]
public void CoerceCaretIndex_Doesnt_Cause_Exception_with_malformed_line_ending() public void CoerceCaretIndex_Doesnt_Cause_Exception_with_malformed_line_ending()
{ {

Loading…
Cancel
Save