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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
43 additions and
5 deletions
-
src/Avalonia.Controls/TextBox.cs
-
tests/Avalonia.Controls.UnitTests/TextBoxTests.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(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -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() |
|
|
|
{ |
|
|
|
|