Skip to content

Commit f7538c3

Browse files
author
tznind
committed
Fix MenuBar editing to focus newly created menu items
1 parent e36eca7 commit f7538c3

3 files changed

Lines changed: 3 additions & 19 deletions

File tree

src/MenuBarExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ public static void InsertMenuItem(this MenuItem menuItem, int index, MenuItem it
154154
var items = menuItem.GetMenuItems();
155155
items.Insert(Math.Min(index, items.Count), itemToInsert);
156156
menuItem.SetMenuItems(items);
157+
158+
itemToInsert.SetFocus();
157159
}
158160

159161
/// <summary>

src/MenuTracker.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ private MenuTracker()
2323
/// </summary>
2424
public static MenuTracker Instance { get; } = new();
2525

26-
/// <summary>
27-
/// Gets the currently selected <see cref="MenuItem"/> if any. To work
28-
/// you must subscribe all <see cref="MenuBar"/> to this class so that
29-
/// it can watch <see cref="MenuBar.MenuOpened"/> etc.
30-
/// </summary>
31-
public MenuItem? CurrentlyOpenMenuItem { get; private set; }
3226

3327
/// <summary>
3428
/// Registers listeners for <paramref name="mb"/> to track open/close.
@@ -71,17 +65,6 @@ private void OnPopoverMenuOpenChanged(object? sender, ValueChangedEventArgs<bool
7165
{
7266
if (sender is MenuBarItem menuBarItem)
7367
{
74-
if (e.NewValue) // Menu opened
75-
{
76-
// Set the currently open menu item to the MenuBarItem itself
77-
// The KeyboardManager will use this to enable renaming
78-
this.CurrentlyOpenMenuItem = menuBarItem;
79-
}
80-
else // Menu closed
81-
{
82-
this.CurrentlyOpenMenuItem = null;
83-
}
84-
8568
// Convert empty menus when closing
8669
if (!e.NewValue)
8770
{

src/UI/KeyboardManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ private bool HandleKeyPressInMenu(View focusedView, MenuItem menuItem, Key keyst
111111
OperationManager.Instance.Do(
112112
new AddMenuItemOperation(this.app, menuItem));
113113

114-
ChangeKeyTo(keystroke, Key.CursorDown);
115-
return false;
114+
return true;
116115
}
117116

118117
if (keystroke.ToString( ) == this.keyMap.SetShortcut)

0 commit comments

Comments
 (0)