Browse Source

fix(android): fix SelectedText boundary check and backward selection crash (#21182)

pull/21198/head
Luthfi Tri Atmaja 5 months ago
committed by GitHub
parent
commit
9293ee6bc5
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 9
      src/Android/Avalonia.Android/Platform/Input/TextEditBuffer.cs

9
src/Android/Avalonia.Android/Platform/Input/TextEditBuffer.cs

@ -56,14 +56,19 @@ namespace Avalonia.Android.Platform.Input
{
get
{
if(_textInputMethod.Client is not { } client || Selection.Start < 0 || Selection.End >= client.SurroundingText.Length)
var client = _textInputMethod.Client;
var text = client?.SurroundingText;
if (string.IsNullOrEmpty(text))
{
return "";
}
var selection = Selection;
var start = Math.Max(0, selection.Start);
var end = Math.Min(text.Length, selection.End);
return client.SurroundingText.Substring(selection.Start, selection.End - selection.Start);
return start >= end ? "" : text.Substring(start, end - start);
}
}

Loading…
Cancel
Save