Browse Source
Ensure SurroundingText is empty for empty line (#16710)
Co-authored-by: Max Katz <maxkatz6@outlook.com>
pull/16705/head
Julien Lebosquain
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
30 additions and
2 deletions
-
src/Avalonia.Controls/TextBoxTextInputMethodClient.cs
-
tests/Avalonia.Controls.UnitTests/TextBoxTests.cs
|
|
|
@ -180,6 +180,11 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
private static string GetTextLineText(TextLine textLine) |
|
|
|
{ |
|
|
|
if (textLine.Length == 0) |
|
|
|
{ |
|
|
|
return string.Empty; |
|
|
|
} |
|
|
|
|
|
|
|
var builder = StringBuilderCache.Acquire(textLine.Length); |
|
|
|
|
|
|
|
foreach (var run in textLine.TextRuns) |
|
|
|
|
|
|
|
@ -9,11 +9,10 @@ using Avalonia.Data; |
|
|
|
using Avalonia.Headless; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.Input.Platform; |
|
|
|
using Avalonia.Input.TextInput; |
|
|
|
using Avalonia.Layout; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.Platform; |
|
|
|
using Avalonia.Rendering; |
|
|
|
using Avalonia.Rendering.Composition; |
|
|
|
using Avalonia.UnitTests; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
using Moq; |
|
|
|
@ -1492,6 +1491,30 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void InputMethodClient_SurroundingText_Returns_Empty_For_Empty_Line() |
|
|
|
{ |
|
|
|
using var _ = UnitTestApplication.Start(Services); |
|
|
|
|
|
|
|
var textBox = new TextBox |
|
|
|
{ |
|
|
|
Template = CreateTemplate(), |
|
|
|
Text = "", |
|
|
|
CaretIndex = 0 |
|
|
|
}; |
|
|
|
textBox.ApplyTemplate(); |
|
|
|
|
|
|
|
var eventArgs = new TextInputMethodClientRequestedEventArgs |
|
|
|
{ |
|
|
|
RoutedEvent = InputElement.TextInputMethodClientRequestedEvent |
|
|
|
}; |
|
|
|
textBox.RaiseEvent(eventArgs); |
|
|
|
|
|
|
|
var client = eventArgs.Client; |
|
|
|
Assert.NotNull(client); |
|
|
|
Assert.Equal(string.Empty, client.SurroundingText); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Backspace_Should_Delete_Last_Character_In_Line_And_Keep_Caret_On_Same_Line() |
|
|
|
{ |
|
|
|
|