From a88002861bc17e14d7ce31b340f7c665e2fc069e Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sat, 6 Dec 2025 19:48:18 +0100 Subject: [PATCH] Fixed: CPMenu items appearing on the wrong side of the menu bar --- AppKit/CPMenu/CPMenu.j | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/AppKit/CPMenu/CPMenu.j b/AppKit/CPMenu/CPMenu.j index 6c23e1408..297171d12 100644 --- a/AppKit/CPMenu/CPMenu.j +++ b/AppKit/CPMenu/CPMenu.j @@ -269,7 +269,8 @@ var _CPMenuBarVisible = NO, if (self) { _title = aTitle; - _items = []; + // Use CPMutableArray instead of raw JS array for consistency with removeAllItems + _items = [CPMutableArray array]; _autoenablesItems = YES; _showsStateColumn = YES; @@ -374,6 +375,10 @@ var _CPMenuBarVisible = NO, [self willChangeValueForKey:@"items"]; _items = [CPMutableArray array]; [self didChangeValueForKey:@"items"]; + + // Ensure the main menu updates if cleared + if (self === [CPApp mainMenu] && _CPMenuBarSharedWindow) + [_CPMenuBarSharedWindow setMenu:self]; } /*! @@ -1223,6 +1228,11 @@ var _CPMenuBarVisible = NO, postNotificationName:CPMenuDidAddItemNotification object:self userInfo:@{ @"CPMenuItemIndex": anIndex }]; + + // FIX #1222: If this is the main menu, force the shared menu bar window to refresh its layout. + // This ensures new items are positioned correctly (e.g. not pushed to the far right by previous layout states). + if (self === [CPApp mainMenu] && _CPMenuBarSharedWindow) + [_CPMenuBarSharedWindow setMenu:self]; } - (void)removeObjectFromItemsAtIndex:(CPUInteger)anIndex @@ -1238,6 +1248,10 @@ var _CPMenuBarVisible = NO, postNotificationName:CPMenuDidRemoveItemNotification object:self userInfo:@{ @"CPMenuItemIndex": anIndex }]; + + // FIX #1222: Ensure the shared menu bar updates layout when items are removed. + if (self === [CPApp mainMenu] && _CPMenuBarSharedWindow) + [_CPMenuBarSharedWindow setMenu:self]; } @end @@ -1331,4 +1345,3 @@ var CPMenuTitleKey = @"CPMenuTitleKey", @import "_CPMenuBarWindow.j" @import "_CPMenuWindow.j" -