Skip to content

Commit

Permalink
Fixes #2892 for v1 - Null reference pressing menu shortcuts when menu…
Browse files Browse the repository at this point in the history
…s have separators (#2955)
  • Loading branch information
BDisp authored Nov 6, 2023
1 parent 2083773 commit d51322a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Terminal.Gui/Views/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,11 @@ bool FindAndOpenChildrenMenuByHotkey (KeyEvent kb, MenuItem [] children)
var c = ((uint)kb.Key & (uint)Key.CharMask);
for (int i = 0; i < children.Length; i++) {
var mi = children [i];

if (mi == null) {
continue;
}

int p = mi.Title.IndexOf (MenuBar.HotKeySpecifier);
if (p != -1 && p + 1 < mi.Title.RuneCount) {
if (Char.ToUpperInvariant ((char)mi.Title [p + 1]) == c) {
Expand Down
15 changes: 15 additions & 0 deletions UnitTests/Menus/MenuTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1809,5 +1809,20 @@ public void Visible_False_Key_Does_Not_Open_And_Close_All_Opened_Menus ()
Assert.True (menu.ProcessHotKey (new KeyEvent (menu.Key, new KeyModifiers ())));
Assert.False (menu.IsMenuOpen);
}

[Fact]
public void Separators_Does_Not_Throws_Pressing_Menu_Shortcut ()
{
var menu = new MenuBar (new MenuBarItem [] {
new MenuBarItem ("File", new MenuItem [] {
new MenuItem ("_New", "", null),
null,
new MenuItem ("_Quit", "", null)
})
});

var exception = Record.Exception (() => Assert.True (menu.ProcessHotKey (new KeyEvent (Key.AltMask | Key.Q, new KeyModifiers () { Alt = true }))));
Assert.Null (exception);
}
}
}

0 comments on commit d51322a

Please sign in to comment.