Skip to content

Commit 056df96

Browse files
authored
Merge pull request #1126 from ychin/fix-winbar-menu-off-by-one
Fix WinBar menus in GUI, and off-by-one error when adding new menus
2 parents e6e4429 + 5e4da5b commit 056df96

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/MacVim/MMVimController.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
static NSString * const MMToolbarMenuName = @"ToolBar";
4444
static NSString * const MMTouchbarMenuName = @"TouchBar";
45+
static NSString * const MMWinBarMenuName = @"WinBar";
4546
static NSString * const MMPopUpMenuPrefix = @"PopUp";
4647
static NSString * const MMUserPopUpMenuPrefix = @"]";
4748

@@ -1242,6 +1243,11 @@ - (void)addMenuWithDescriptor:(NSArray *)desc atIndex:(int)idx
12421243
return;
12431244
}
12441245

1246+
if ([rootName isEqual:MMWinBarMenuName]) {
1247+
// WinBar menus are completed handled within Vim windows. No need for GUI to do anything.
1248+
return;
1249+
}
1250+
12451251
// This is either a main menu item or a popup menu item.
12461252
NSString *title = [desc lastObject];
12471253
NSMenuItem *item = [[NSMenuItem alloc] init];
@@ -1261,7 +1267,10 @@ - (void)addMenuWithDescriptor:(NSArray *)desc atIndex:(int)idx
12611267
} else {
12621268
// If descriptor has no parent and its not a popup (or toolbar) menu,
12631269
// then it must belong to main menu.
1264-
if (!parent) parent = mainMenu;
1270+
if (!parent) {
1271+
parent = mainMenu;
1272+
idx += 1; // Main menu already has the application menu as the first item, so everything else must be shifted by one.
1273+
}
12651274

12661275
if ([parent numberOfItems] <= idx) {
12671276
[parent addItem:item];
@@ -1311,6 +1320,11 @@ - (void)addMenuItemWithDescriptor:(NSArray *)desc
13111320
#endif
13121321
return;
13131322
}
1323+
if ([rootName isEqual:MMWinBarMenuName]) {
1324+
// WinBar menus are completed handled within Vim windows. No need for GUI to do anything.
1325+
return;
1326+
}
1327+
13141328
NSMenu *parent = [self parentMenuForDescriptor:desc];
13151329
if (!parent) {
13161330
ASLogWarn(@"Menu item '%@' has no parent",

0 commit comments

Comments
 (0)