Fixes #2892 for v1 - Null reference pressing menu shortcuts when menus have separators (#2955)

This commit is contained in:
BDisp
2023-11-06 21:38:37 +00:00
committed by GitHub
parent 20837733a7
commit d51322ad17
2 changed files with 20 additions and 0 deletions

View File

@@ -1677,6 +1677,11 @@ namespace Terminal.Gui {
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) {

View File

@@ -1809,5 +1809,20 @@ Edit
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);
}
}
}