Browse Source

Don't throw on unexpected iOS input (#20728)

* Don't throw on unexpected iOS input

* Improve normalization
pull/14481/merge
kerams 3 weeks ago
committed by GitHub
parent
commit
dafa53a49c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 27
      src/iOS/Avalonia.iOS/TextInputResponder.cs

27
src/iOS/Avalonia.iOS/TextInputResponder.cs

@ -34,14 +34,10 @@ partial class AvaloniaView
public AvaloniaTextRange(int startIndex, int endIndex) public AvaloniaTextRange(int startIndex, int endIndex)
{ {
if (startIndex < 0) var a = Math.Max(0, startIndex);
throw new ArgumentOutOfRangeException(nameof(startIndex)); var b = Math.Max(0, endIndex);
StartIndex = Math.Min(a, b);
if (endIndex < startIndex) EndIndex = Math.Max(a, b);
throw new ArgumentOutOfRangeException(nameof(endIndex));
StartIndex = startIndex;
EndIndex = endIndex;
} }
public override bool IsEmpty => StartIndex == EndIndex; public override bool IsEmpty => StartIndex == EndIndex;
@ -58,9 +54,7 @@ partial class AvaloniaView
{ {
public AvaloniaTextPosition(int index) public AvaloniaTextPosition(int index)
{ {
if (index < 0) Index = Math.Max(0, index);
throw new ArgumentOutOfRangeException(nameof(index));
Index = index;
} }
public int Index { get; } public int Index { get; }
@ -509,14 +503,15 @@ partial class AvaloniaView
{ {
if (_inSurroundingTextUpdateEvent > 0) if (_inSurroundingTextUpdateEvent > 0)
return; return;
if (value == null)
_client.Selection = default;
else
{
var r = (AvaloniaTextRange)value;
if (value is AvaloniaTextRange r)
{
_client.Selection = new TextSelection(r.StartIndex, r.EndIndex); _client.Selection = new TextSelection(r.StartIndex, r.EndIndex);
} }
else
{
_client.Selection = default;
}
} }
} }

Loading…
Cancel
Save