Browse Source

Handle preedit

pull/8963/head
Benedikt Stebner 3 years ago
parent
commit
8bc0c5f5aa
  1. 2
      src/Avalonia.Base/Input/TextInput/ITextInputMethodClient.cs
  2. 35
      src/Web/Avalonia.Web.Blazor/AvaloniaView.razor.cs

2
src/Avalonia.Base/Input/TextInput/ITextInputMethodClient.cs

@ -28,7 +28,7 @@ namespace Avalonia.Input.TextInput
/// <summary>
/// Sets the non-committed input string
/// </summary>
void SetPreeditText(string text);
void SetPreeditText(string? text);
/// <summary>
/// Indicates if text input client is capable of providing the text around the cursor
/// </summary>

35
src/Web/Avalonia.Web.Blazor/AvaloniaView.razor.cs

@ -335,7 +335,23 @@ namespace Avalonia.Web.Blazor
private void InputHelperOnCompositionEvent(object? sender, WebCompositionEventArgs e)
{
Debug.WriteLine("Test");
if(_client == null)
{
return;
}
switch (e.Type)
{
case WebCompositionEventArgs.WebCompositionEventType.Start:
_client.SetPreeditText(null);
break;
case WebCompositionEventArgs.WebCompositionEventType.Update:
_client?.SetPreeditText(e.Data);
break;
case WebCompositionEventArgs.WebCompositionEventType.End:
_client?.SetPreeditText(null);
break;
}
}
private void OnRenderFrame()
@ -417,6 +433,16 @@ namespace Avalonia.Web.Blazor
return;
}
if(_client != null)
{
_client.SurroundingTextChanged -= SurroundingTextChanged;
}
if(client != null)
{
client.SurroundingTextChanged += SurroundingTextChanged;
}
_inputHelper.Clear();
_client = client;
@ -434,6 +460,13 @@ namespace Avalonia.Web.Blazor
}
}
private void SurroundingTextChanged(object? sender, EventArgs e)
{
var surroundingText = _client.SurroundingText;
_inputHelper?.SetSurroundingText(surroundingText.Text, surroundingText.AnchorOffset, surroundingText.CursorOffset);
}
public void SetCursorRect(Rect rect)
{
}

Loading…
Cancel
Save