Browse Source

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

release/latest
Luthfi Tri Atmaja 6 months ago
committed by Julien Lebosquain
parent
commit
475d364fd4
  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 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 ""; return "";
} }
var selection = Selection; 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