diff --git a/widget/cocoa/nsMenuBarX.mm b/widget/cocoa/nsMenuBarX.mm index 9ce72f0eccb2..35f8698b00ed 100644 --- a/widget/cocoa/nsMenuBarX.mm +++ b/widget/cocoa/nsMenuBarX.mm @@ -492,7 +492,15 @@ nsresult nsMenuBarX::Paint() { NS_OBJC_END_TRY_ABORT_BLOCK; NS_OBJC_BEGIN_TRY_ABORT_BLOCK; - RemoveProblematicMenuItems(mNativeMenu); + // If the user switches to another app and back to the last open window, we + // should not remove the problematic menu items again or the emoji picker + // would not be able to be opened again via shortcuts. This should be the only + // time that `sLastGeckoMenuBarPainted` is checked in this method, since other + // optimizations could interfere with menu manipulations by native dialogs and + // similar (see comment above). + if (nsMenuBarX::sLastGeckoMenuBarPainted != this) { + RemoveProblematicMenuItems(mNativeMenu); + } NS_OBJC_END_TRY_ABORT_BLOCK; NS_OBJC_BEGIN_TRY_ABORT_BLOCK; diff --git a/widget/cocoa/nsMenuX.h b/widget/cocoa/nsMenuX.h index cdc5884a99e3..7e2417f15a22 100644 --- a/widget/cocoa/nsMenuX.h +++ b/widget/cocoa/nsMenuX.h @@ -180,6 +180,7 @@ class nsMenuX final : public nsMenuParentX, static bool IsXULHelpMenu(nsIContent* aMenuContent); static bool IsXULWindowMenu(nsIContent* aMenuContent); + static bool IsXULEditMenu(nsIContent* aMenuContent); // Set an observer that gets notified of menu opening and closing. // The menu does not keep a strong reference the observer. The observer must diff --git a/widget/cocoa/nsMenuX.mm b/widget/cocoa/nsMenuX.mm index 2cf6fd054377..5f3843d451ed 100644 --- a/widget/cocoa/nsMenuX.mm +++ b/widget/cocoa/nsMenuX.mm @@ -141,7 +141,7 @@ nsMenuX::nsMenuX(nsMenuParentX* aParent, nsMenuGroupOwnerX* aMenuGroupOwner, mIcon = MakeUnique(this); if (mVisible) { - if (!isXULWindowMenu) { + if (!isXULWindowMenu && !IsXULEditMenu(mContent)) { SetRebuild(true); } SetupIcon(); @@ -1012,6 +1012,18 @@ bool nsMenuX::IsXULWindowMenu(nsIContent* aMenuContent) { return retval; } +bool nsMenuX::IsXULEditMenu(nsIContent* aMenuContent) { + bool retval = false; + if (aMenuContent && aMenuContent->IsElement()) { + nsAutoString id; + aMenuContent->AsElement()->GetAttr(nsGkAtoms::id, id); + if (id.Equals(u"edit-menu"_ns)) { + retval = true; + } + } + return retval; +} + // // nsChangeObserver //