Browse Source
Merge pull request #3658 from Deadpikle/feature/textbox-selectedtext
Feature: TextBox.SelectedText
pull/3677/head
Steven Kirk
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
59 additions and
0 deletions
-
src/Avalonia.Controls/TextBox.cs
-
tests/Avalonia.Controls.UnitTests/TextBoxTests.cs
|
|
|
@ -275,6 +275,22 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public string SelectedText |
|
|
|
{ |
|
|
|
get { return GetSelection(); } |
|
|
|
set |
|
|
|
{ |
|
|
|
if (value == null) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
_undoRedoHelper.Snapshot(); |
|
|
|
HandleTextInput(value); |
|
|
|
_undoRedoHelper.Snapshot(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the horizontal alignment of the content within the control.
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
@ -385,6 +385,49 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.True(target.SelectionEnd <= "123".Length); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void SelectedText_Changes_OnSelectionChange() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(Services)) |
|
|
|
{ |
|
|
|
var target = new TextBox |
|
|
|
{ |
|
|
|
Template = CreateTemplate(), |
|
|
|
Text = "0123456789" |
|
|
|
}; |
|
|
|
|
|
|
|
Assert.True(target.SelectedText == ""); |
|
|
|
|
|
|
|
target.SelectionStart = 2; |
|
|
|
target.SelectionEnd = 4; |
|
|
|
|
|
|
|
Assert.True(target.SelectedText == "23"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void SelectedText_EditsText() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(Services)) |
|
|
|
{ |
|
|
|
var target = new TextBox |
|
|
|
{ |
|
|
|
Template = CreateTemplate(), |
|
|
|
Text = "0123" |
|
|
|
}; |
|
|
|
|
|
|
|
target.SelectedText = "AA"; |
|
|
|
Assert.True(target.Text == "AA0123"); |
|
|
|
|
|
|
|
target.SelectionStart = 1; |
|
|
|
target.SelectionEnd = 3; |
|
|
|
target.SelectedText = "BB"; |
|
|
|
|
|
|
|
Assert.True(target.Text == "ABB123"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CoerceCaretIndex_Doesnt_Cause_Exception_with_malformed_line_ending() |
|
|
|
{ |
|
|
|
|