Fixes #4147. HotKeySpecifier 0xFFFF does not clear HotKey (#4508)

* Initial plan

* Fix: Set HotKey to Key.Empty when HotKeySpecifier is 0xFFFF

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix code style: Use explicit type instead of var for View

Co-authored-by: tig <585482+tig@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
This commit is contained in:
Copilot
2025-12-18 07:20:30 -07:00
committed by GitHub
parent bc897278ed
commit 8f4ad8a7d4
2 changed files with 40 additions and 0 deletions

View File

@@ -225,6 +225,7 @@ public partial class View // Keyboard APIs
{
if (HotKeySpecifier == new Rune ('\xFFFF'))
{
HotKey = Key.Empty;
return; // throw new InvalidOperationException ("Can't set HotKey unless a TextFormatter has been created");
}

View File

@@ -373,4 +373,43 @@ public class HotKeyTests
Assert.Equal ("", view.Title);
Assert.Equal (KeyCode.Null, view.HotKey);
}
[Fact]
public void HotKeySpecifier_0xFFFF_Clears_HotKey ()
{
// Arrange: Create a view with a hotkey
View view = new () { HotKeySpecifier = (Rune)'_', Title = "_Test" };
Assert.Equal (KeyCode.T, view.HotKey);
// Act: Set HotKeySpecifier to 0xFFFF
view.HotKeySpecifier = (Rune)0xFFFF;
// Assert: HotKey should be cleared
Assert.Equal (KeyCode.Null, view.HotKey);
}
[Fact]
public void HotKeySpecifier_0xFFFF_Before_Title_Set_Prevents_HotKey ()
{
// Arrange & Act: Set HotKeySpecifier to 0xFFFF before setting Title
View view = new () { HotKeySpecifier = (Rune)0xFFFF };
view.Title = "_Test";
// Assert: HotKey should remain empty
Assert.Equal (KeyCode.Null, view.HotKey);
}
[Fact]
public void HotKeySpecifier_0xFFFF_With_Underscore_In_Title ()
{
// Arrange & Act: This is the scenario from the bug report
View view = new ()
{
HotKeySpecifier = (Rune)0xFFFF,
Title = "my label with an _underscore"
};
// Assert: HotKey should be empty (no hotkey should be set)
Assert.Equal (KeyCode.Null, view.HotKey);
}
}