File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
components/customizableui Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -495,6 +495,9 @@ document.addEventListener(
495495 ToolbarContextMenu . updateDownloadsAlwaysOpenPanel ( event . target ) ;
496496 ToolbarContextMenu . updateExtensionsButtonContextMenu ( event . target ) ;
497497 ToolbarContextMenu . updateExtension ( event . target ) ;
498+ // hideLeadingSeparatorIfNeeded must be called last after updating the menu items above,
499+ // as they may change which items are visible.
500+ ToolbarContextMenu . hideLeadingSeparatorIfNeeded ( event . target ) ;
498501 break ;
499502 case "pageActionContextMenu" :
500503 BrowserPageActions . onContextMenuShowing ( event , event . target ) ;
Original file line number Diff line number Diff line change @@ -553,4 +553,30 @@ export var ToolbarContextMenu = {
553553 let id = this . _getExtensionId ( popup ) ;
554554 await BrowserAddonUI . manageAddon ( id , "browserAction" ) ;
555555 } ,
556+
557+ /**
558+ * Hides the first visible menu separator if it would appear at the top of the
559+ * toolbar context menu (i.e., when all preceding menu items are hidden). This
560+ * prevents a separator from appearing at the top of the menu with no items above it.
561+ *
562+ * Fix for Bug 1955241.
563+ *
564+ * @param {Element } popup
565+ * The toolbar-context-menu element for a window.
566+ */
567+ hideLeadingSeparatorIfNeeded ( popup ) {
568+ // Find the first non-hidden element in the menu
569+ let firstVisibleElement = popup . firstElementChild ;
570+ while ( firstVisibleElement && firstVisibleElement . hidden ) {
571+ firstVisibleElement = firstVisibleElement . nextElementSibling ;
572+ }
573+
574+ // If the first visible element is a separator, hide it
575+ if (
576+ firstVisibleElement &&
577+ firstVisibleElement . localName === "menuseparator"
578+ ) {
579+ firstVisibleElement . hidden = true ;
580+ }
581+ } ,
556582} ;
You can’t perform that action at this time.
0 commit comments