Browse Source

Allow copying and cutting revealed TextBox passwords (#21710)

fix/osx-ax-visible-children
yoyo 3 months ago
committed by GitHub
parent
commit
4e0632cf42
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 10
      src/Avalonia.Controls/TextBox.cs
  2. 34
      tests/Avalonia.Controls.UnitTests/TextBoxTests.cs

10
src/Avalonia.Controls/TextBox.cs

@ -1041,7 +1041,9 @@ namespace Avalonia.Controls
UpdatePseudoclasses();
UpdateCommandStates();
}
else if (change.Property == IsReadOnlyProperty || change.Property == PasswordCharProperty)
else if (change.Property == IsReadOnlyProperty ||
change.Property == PasswordCharProperty ||
change.Property == RevealPasswordProperty)
{
UpdateCommandStates();
}
@ -1746,7 +1748,7 @@ namespace Avalonia.Controls
else
{
// We select the current held word, or the whole hidden content
if (IsPasswordBox && !RevealPassword)
if (IsPasswordBox)
{
_wordSelectionStart = -1;
@ -1881,7 +1883,7 @@ namespace Avalonia.Controls
private void SelectWord(string text, int caretIndex, int selectionStart, int selectionEnd)
{
if (IsPasswordBox && !RevealPassword)
if (IsPasswordBox)
{
// double-clicking in a cloaked single-line password box selects all text
// see https://github.com/AvaloniaUI/Avalonia/issues/14956
@ -2530,7 +2532,7 @@ namespace Avalonia.Controls
PseudoClasses.Set(":touch-mode", _isInTouchMode);
}
private bool IsPasswordBox => PasswordChar != default(char);
private bool IsPasswordBox => PasswordChar != default(char) && !RevealPassword;
UndoRedoState UndoRedoHelper<UndoRedoState>.IUndoRedoHost.UndoRedoState
{

34
tests/Avalonia.Controls.UnitTests/TextBoxTests.cs

@ -1527,6 +1527,40 @@ namespace Avalonia.Controls.UnitTests
}
}
[Fact]
public void Command_States_Update_When_RevealPassword_Changes()
{
using (UnitTestApplication.Start(Services))
{
var tb = new TextBox
{
Template = CreateTemplate(),
Text = "1234",
PasswordChar = '*',
SelectionStart = 1,
SelectionEnd = 3,
};
tb.Measure(Size.Infinity);
Assert.False(tb.CanCopy);
Assert.False(tb.CanCut);
Assert.True(tb.CanPaste);
tb.RevealPassword = true;
Assert.True(tb.CanCopy);
Assert.True(tb.CanCut);
Assert.True(tb.CanPaste);
tb.RevealPassword = false;
Assert.False(tb.CanCopy);
Assert.False(tb.CanCut);
Assert.True(tb.CanPaste);
}
}
[Fact]
public void ReadOnly_Editing_Hotkeys_Do_Not_Modify_Text_Or_Undo_State()
{

Loading…
Cancel
Save