Browse Source

Merge pull request #3748 from Deadpikle/fix/selected-text-no-clear

Fix TextBox.SelectedText = "" not clearing text
pull/3763/head
Benedikt Stebner 6 years ago
committed by GitHub
parent
commit
671d234d47
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/Avalonia.Controls/TextBox.cs
  2. 36
      tests/Avalonia.Controls.UnitTests/TextBoxTests.cs

12
src/Avalonia.Controls/TextBox.cs

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

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

@ -425,6 +425,42 @@ namespace Avalonia.Controls.UnitTests
}
}
[Fact]
public void SelectedText_CanClearText()
{
using (UnitTestApplication.Start(Services))
{
var target = new TextBox
{
Template = CreateTemplate(),
Text = "0123"
};
target.SelectionStart = 1;
target.SelectionEnd = 3;
target.SelectedText = "";
Assert.True(target.Text == "03");
}
}
[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]
public void CoerceCaretIndex_Doesnt_Cause_Exception_with_malformed_line_ending()
{

Loading…
Cancel
Save