From d1200e1e4727baa1232e05749d64252d14952bcf Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Thu, 3 May 2018 22:43:18 +0100 Subject: [PATCH] protect against copy and cut. --- src/Avalonia.Controls/TextBox.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 78ef532a26..df68a01722 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -126,7 +126,7 @@ namespace Avalonia.Controls this.GetObservable(TextProperty).Subscribe(text => { - if (PasswordChar != default(char)) + if (IsPasswordBox) { DisplayText = new string(PasswordChar, text.Length); } @@ -345,7 +345,7 @@ namespace Avalonia.Controls private async void Copy() { await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))) - .SetTextAsync(GetSelection()); + .SetTextAsync(GetSelection()); } private async void Paste() @@ -379,7 +379,10 @@ namespace Avalonia.Controls case Key.C: if (modifiers == InputModifiers.Control) { - Copy(); + if (!IsPasswordBox) + { + Copy(); + } handled = true; } break; @@ -387,8 +390,11 @@ namespace Avalonia.Controls case Key.X: if (modifiers == InputModifiers.Control) { - Copy(); - DeleteSelection(); + if (!IsPasswordBox) + { + Copy(); + DeleteSelection(); + } handled = true; } break; @@ -886,6 +892,8 @@ namespace Avalonia.Controls SelectionEnd = CaretIndex; } + private bool IsPasswordBox => PasswordChar != default(char); + UndoRedoState UndoRedoHelper.IUndoRedoHost.UndoRedoState { get { return new UndoRedoState(Text, CaretIndex); }