Browse Source

Expose Cut Copy and Paste methods for binding for context menus

pull/4505/head
Jumar Macato 6 years ago
parent
commit
43b94e997c
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 21
      src/Avalonia.Controls/TextBox.cs

21
src/Avalonia.Controls/TextBox.cs

@ -417,7 +417,7 @@ namespace Avalonia.Controls
SelectionEnd = 0; SelectionEnd = 0;
RevealPassword = false; RevealPassword = false;
} }
_presenter?.HideCaret(); _presenter?.HideCaret();
} }
@ -460,13 +460,21 @@ namespace Avalonia.Controls
return text; 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))) await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard)))
.SetTextAsync(GetSelection()); .SetTextAsync(GetSelection());
} }
private async void Paste() public async void Paste()
{ {
var text = await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))).GetTextAsync(); var text = await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))).GetTextAsync();
if (text == null) if (text == null)
@ -511,23 +519,18 @@ namespace Avalonia.Controls
{ {
if (!IsPasswordBox) if (!IsPasswordBox)
{ {
_undoRedoHelper.Snapshot(); Cut();
Copy();
DeleteSelection();
_undoRedoHelper.Snapshot();
} }
handled = true; handled = true;
} }
else if (Match(keymap.Paste)) else if (Match(keymap.Paste))
{ {
Paste(); Paste();
handled = true; handled = true;
} }
else if (Match(keymap.Undo)) else if (Match(keymap.Undo))
{ {
try try
{ {
_isUndoingRedoing = true; _isUndoingRedoing = true;

Loading…
Cancel
Save