Skip to content

Commit

Permalink
Required changes
Browse files Browse the repository at this point in the history
  • Loading branch information
c4llv07e committed Dec 13, 2024
1 parent 378ed40 commit 0acc9f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Avalonia.Controls/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ protected override void OnKeyDown(KeyEventArgs e)
}
else
{
// It's not secure to rely on password field content when moving.
bool hasWholeWordModifiers = modifiers.HasAllFlags(keymap.WholeWordTextActionModifiers) && !IsPasswordBox;
switch (e.Key)
{
Expand Down
21 changes: 21 additions & 0 deletions tests/Avalonia.Controls.UnitTests/TextBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ public void DefaultBindingMode_Should_Be_TwoWay()
TextBox.TextProperty.GetMetadata(typeof(TextBox)).DefaultBindingMode);
}

[Fact]
public void TextBox_Ignore_Word_Move_In_Password_Field()
{
using (UnitTestApplication.Start(Services))
{
var target = new TextBox
{
Template = CreateTemplate(),
PasswordChar = '*',
Text = "passw0rd"
};

target.ApplyTemplate();
target.Measure(Size.Infinity);
target.CaretIndex = 8;
RaiseKeyEvent(target, Key.Left, KeyModifiers.Control);

Assert.Equal(7, target.CaretIndex);
}
}

[Fact]
public void CaretIndex_Can_Moved_To_Position_After_The_End_Of_Text_With_Arrow_Key()
{
Expand Down

0 comments on commit 0acc9f0

Please sign in to comment.