Browse Source

Expose Cut Copy and Paste methods for binding for context menus

pull/4531/head
Jumar Macato 6 years ago
committed by Dan Walmsley
parent
commit
bb8e594e58
  1. 21
      src/Avalonia.Controls/TextBox.cs

21
src/Avalonia.Controls/TextBox.cs

@ -424,7 +424,7 @@ namespace Avalonia.Controls
ClearSelection();
RevealPassword = false;
}
_presenter?.HideCaret();
}
@ -467,13 +467,21 @@ namespace Avalonia.Controls
return text;
}
private async void Copy()
public async void Cut()
{
_undoRedoHelper.Snapshot();
Copy();
DeleteSelection();
_undoRedoHelper.Snapshot();
}
public async void Copy()
{
await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard)))
.SetTextAsync(GetSelection());
}
private async void Paste()
public async void Paste()
{
var text = await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))).GetTextAsync();
if (text == null)
@ -518,23 +526,18 @@ namespace Avalonia.Controls
{
if (!IsPasswordBox)
{
_undoRedoHelper.Snapshot();
Copy();
DeleteSelection();
_undoRedoHelper.Snapshot();
Cut();
}
handled = true;
}
else if (Match(keymap.Paste))
{
Paste();
handled = true;
}
else if (Match(keymap.Undo))
{
try
{
_isUndoingRedoing = true;

Loading…
Cancel
Save