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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
35 additions and
0 deletions
-
src/Avalonia.Base/Input/TextInput/TextInputMethodClient.cs
-
src/Avalonia.Controls/TextBoxTextInputMethodClient.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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -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) |
|
|
|
|