Browse Source

add api to allow text input method to trigger common context menu actions (#15666)

pull/15670/head
Emmanuel Hansen 2 years ago
committed by GitHub
parent
commit
a7f7d80019
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 14
      src/Avalonia.Base/Input/TextInput/TextInputMethodClient.cs
  2. 21
      src/Avalonia.Controls/TextBoxTextInputMethodClient.cs

14
src/Avalonia.Base/Input/TextInput/TextInputMethodClient.cs

@ -64,6 +64,12 @@ namespace Avalonia.Input.TextInput
/// </summary>
public virtual void SetPreeditText(string? preeditText) { }
/// <summary>
/// Execute specific context menu actions
/// </summary>
/// <param name="action">The <see cref="ContextMenuAction"/> to perform</param>
public virtual void ExecuteContextMenuAction(ContextMenuAction action) { }
/// <summary>
/// Sets the non-committed input string and cursor offset in that string
/// </summary>
@ -99,4 +105,12 @@ namespace Avalonia.Input.TextInput
}
public record struct TextSelection(int Start, int End);
public enum ContextMenuAction
{
Copy,
Cut,
Paste,
SelectAll
}
}

21
src/Avalonia.Controls/TextBoxTextInputMethodClient.cs

@ -184,6 +184,27 @@ namespace Avalonia.Controls
return lineText;
}
public override void ExecuteContextMenuAction(ContextMenuAction action)
{
base.ExecuteContextMenuAction(action);
switch (action)
{
case ContextMenuAction.Copy:
_parent?.Copy();
break;
case ContextMenuAction.Cut:
_parent?.Cut();
break;
case ContextMenuAction.Paste:
_parent?.Paste();
break;
case ContextMenuAction.SelectAll:
_parent?.SelectAll();
break;
}
}
private void OnParentPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{
if (e.Property == TextBox.TextProperty)

Loading…
Cancel
Save