Browse Source

protect against copy and cut.

Dan Walmsley 7 years ago
parent
commit
d1200e1e47
1 changed files with 13 additions and 5 deletions
  1. 13 5
      src/Avalonia.Controls/TextBox.cs

+ 13 - 5
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<UndoRedoState>.IUndoRedoHost.UndoRedoState
         {
             get { return new UndoRedoState(Text, CaretIndex); }