diff --git a/Terminal.Gui/ViewBase/View.Keyboard.cs b/Terminal.Gui/ViewBase/View.Keyboard.cs index 867b324b6..5e864abf7 100644 --- a/Terminal.Gui/ViewBase/View.Keyboard.cs +++ b/Terminal.Gui/ViewBase/View.Keyboard.cs @@ -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"); } diff --git a/Tests/UnitTestsParallelizable/ViewBase/Keyboard/HotKeyTests.cs b/Tests/UnitTestsParallelizable/ViewBase/Keyboard/HotKeyTests.cs index 715733e81..2deb0a615 100644 --- a/Tests/UnitTestsParallelizable/ViewBase/Keyboard/HotKeyTests.cs +++ b/Tests/UnitTestsParallelizable/ViewBase/Keyboard/HotKeyTests.cs @@ -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); + } }