Browse Source

Android adjustments

pull/11848/head
Benedikt Stebner 3 years ago
parent
commit
cee239b142
  1. 2
      src/Android/Avalonia.Android/AndroidInputMethod.cs
  2. 36
      src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs

2
src/Android/Avalonia.Android/AndroidInputMethod.cs

@ -107,6 +107,8 @@ namespace Avalonia.Android
var selection = Client.Selection;
_imm.UpdateSelection(_host, selection.Start, selection.End, selection.Start, selection.End);
_inputConnection.SetSelection(selection.Start, selection.End);
}
private void _client_SurroundingTextChanged(object sender, EventArgs e)

36
src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs

@ -29,6 +29,7 @@ using Avalonia.Platform.Storage;
using Avalonia.Rendering;
using Avalonia.Rendering.Composition;
using Java.Lang;
using static System.Net.Mime.MediaTypeNames;
using ClipboardManager = Android.Content.ClipboardManager;
namespace Avalonia.Android.Platform.SkiaPlatform
@ -459,9 +460,7 @@ namespace Avalonia.Android.Platform.SkiaPlatform
{
var text = tb.SubSequence(0, tb.Length());
//System.Diagnostics.Debug.WriteLine($"Replace: start: {start}, end: {end}, text: {text}");
_inputConnection.InputMethod.Client.Selection = new TextSelection(start, end);
SelectSurroundingTextForDeletion(start, end, text);
}
return base.Replace(start, end, tb);
@ -473,13 +472,18 @@ namespace Avalonia.Android.Platform.SkiaPlatform
{
var text = tb.SubSequence(tbstart, tbend);
//System.Diagnostics.Debug.WriteLine($"Replace: start: {start}, end: {end}, text: {text}");
_inputConnection.InputMethod.Client.Selection = new TextSelection(start, end);
SelectSurroundingTextForDeletion(start, end, text);
}
return base.Replace(start, end, tb, tbstart, tbend);
}
private void SelectSurroundingTextForDeletion(int start, int end, string text)
{
_inputConnection.InputMethod.Client.Selection = new TextSelection(start, end);
//_inputConnection.Toplevel.TextInput(text);
}
}
internal class AvaloniaInputConnection : BaseInputConnection
@ -507,6 +511,8 @@ namespace Avalonia.Android.Platform.SkiaPlatform
public IAndroidInputMethod InputMethod => _inputMethod;
public TopLevelImpl Toplevel => _toplevel;
public override bool SetComposingText(ICharSequence text, int newCursorPosition)
{
_compositionText = text.SubSequence(0, text.Length());
@ -551,6 +557,24 @@ namespace Avalonia.Android.Platform.SkiaPlatform
return ret;
}
public override bool DeleteSurroundingText(int beforeLength, int afterLength)
{
if (InputMethod.IsActive)
{
EditableWrapper.IgnoreChange = true;
var selection = InputMethod.Client.Selection;
InputMethod.Client.Selection = new TextSelection(selection.Start - beforeLength, selection.Start + afterLength);
Toplevel.TextInput("");
EditableWrapper.IgnoreChange = true;
}
return base.DeleteSurroundingText(beforeLength, afterLength);
}
public override bool PerformEditorAction([GeneratedEnum] ImeAction actionCode)
{
switch (actionCode)

Loading…
Cancel
Save