|
|
|
@ -285,14 +285,14 @@ namespace Avalonia.Android.Platform.Input |
|
|
|
public ICharSequence? GetTextAfterCursorFormatted(int n, [GeneratedEnum] GetTextFlags flags) |
|
|
|
{ |
|
|
|
var end = Math.Min(_editBuffer.Selection.End, _editBuffer.Text.Length); |
|
|
|
return new Java.Lang.String(_editBuffer.Text.Substring(end, Math.Min(n, _editBuffer.Text.Length - end))); |
|
|
|
return SafeSubstring(_editBuffer.Text, end, Math.Min(n, _editBuffer.Text.Length - end)); |
|
|
|
} |
|
|
|
|
|
|
|
public ICharSequence? GetTextBeforeCursorFormatted(int n, [GeneratedEnum] GetTextFlags flags) |
|
|
|
{ |
|
|
|
var start = Math.Max(0, _editBuffer.Selection.Start - n); |
|
|
|
var length = _editBuffer.Selection.Start - start; |
|
|
|
return _editBuffer.Text == null ? null : new Java.Lang.String(_editBuffer.Text.Substring(start, length)); |
|
|
|
return SafeSubstring(_editBuffer.Text, start, length); |
|
|
|
} |
|
|
|
|
|
|
|
public bool PerformPrivateCommand(string? action, Bundle? data) |
|
|
|
@ -330,5 +330,13 @@ namespace Avalonia.Android.Platform.Input |
|
|
|
EndBatchEdit(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static ICharSequence? SafeSubstring(string? text, int start, int length) |
|
|
|
{ |
|
|
|
if (text == null || text.Length < start + length) |
|
|
|
return null; |
|
|
|
else |
|
|
|
return new Java.Lang.String(text.Substring(start, length)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|