Skip to content

Commit 1e0d314

Browse files
zrt2399MrJul
authored andcommitted
fix(TextBox): initialize command states in constructor (#21859)
1 parent 05b1807 commit 1e0d314

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/Avalonia.Controls/TextBox.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ public TextBox()
431431
_undoRedoHelper = new UndoRedoHelper<UndoRedoState>(this);
432432
_selectedTextChangesMadeSinceLastUndoSnapshot = 0;
433433
_hasDoneSnapshotOnce = false;
434+
UpdateCommandStates();
434435
UpdatePseudoclasses();
435436
}
436437

tests/Avalonia.Controls.UnitTests/TextBoxTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,19 @@ public void Setting_IsUndoEnabled_To_False_Clears_Undo_Redo()
15491549
}
15501550
}
15511551

1552+
[Fact]
1553+
public void Empty_TextBox_Initializes_Clipboard_Command_States()
1554+
{
1555+
using (UnitTestApplication.Start(Services))
1556+
{
1557+
var tb = new TextBox();
1558+
1559+
Assert.False(tb.CanCopy);
1560+
Assert.False(tb.CanCut);
1561+
Assert.True(tb.CanPaste);
1562+
}
1563+
}
1564+
15521565
[Fact]
15531566
public void Command_States_Update_When_ReadOnly_And_PasswordChar_Change()
15541567
{

0 commit comments

Comments
 (0)