client/context menus: skip consecutive separators

This commit is contained in:
Adorian Doran 2025-11-22 13:33:48 +02:00
parent d0342598c4
commit b4b1b7a3fa

View File

@ -165,16 +165,19 @@ class ContextMenu {
let $group = $parent; // The current group or parent element to which items are being appended let $group = $parent; // The current group or parent element to which items are being appended
let shouldStartNewGroup = false; // If true, the next item will start a new group let shouldStartNewGroup = false; // If true, the next item will start a new group
let shouldResetGroup = false; // If true, the next item will be the last one from the group let shouldResetGroup = false; // If true, the next item will be the last one from the group
let prevItemKind: string = "";
for (let index = 0; index < items.length; index++) { for (let index = 0; index < items.length; index++) {
const item = items[index]; const item = items[index];
const itemKind = ("kind" in item) ? item.kind : "";
if (!item) { if (!item) {
continue; continue;
} }
// If the current item is a header, start a new group. This group will contain the // If the current item is a header, start a new group. This group will contain the
// header and the next item that follows the header. // header and the next item that follows the header.
if ("kind" in item && item.kind === "header") { if (itemKind === "header") {
if (multicolumn && !shouldResetGroup) { if (multicolumn && !shouldResetGroup) {
shouldStartNewGroup = true; shouldStartNewGroup = true;
} }
@ -200,14 +203,18 @@ class ContextMenu {
shouldStartNewGroup = false; shouldStartNewGroup = false;
} }
if ("kind" in item && item.kind === "separator") { if (itemKind === "separator") {
if (prevItemKind === "separator") {
// Skip consecutive separators
continue;
}
$group.append($("<div>").addClass("dropdown-divider")); $group.append($("<div>").addClass("dropdown-divider"));
shouldResetGroup = true; // End the group after the next item shouldResetGroup = true; // End the group after the next item
} else if ("kind" in item && item.kind === "header") { } else if (itemKind === "header") {
$group.append($("<h6>").addClass("dropdown-header").text(item.title)); $group.append($("<h6>").addClass("dropdown-header").text(item.title));
shouldResetGroup = true; shouldResetGroup = true;
} else { } else {
if ("kind" in item && item.kind === "custom") { if (itemKind === "custom") {
// Custom menu item // Custom menu item
$group.append(this.createCustomMenuItem(item)); $group.append(this.createCustomMenuItem(item));
} else { } else {
@ -222,6 +229,9 @@ class ContextMenu {
shouldResetGroup = false; shouldResetGroup = false;
}; };
} }
prevItemKind = itemKind;
} }
} }