Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/context menus: skip consecutive separators
Adorian Doranb4b1b7a3fabb
diff --git a/apps/client/src/menus/context_menu.ts b/apps/client/src/menus/context_menu.tsindex 4e28d77680..32d55085f0 100644--- a/apps/client/src/menus/context_menu.ts+++ b/apps/client/src/menus/context_menu.ts@@ -165,16 +165,19 @@ class ContextMenu {let $group = $parent; // The current group or parent element to which items are being appendedlet shouldStartNewGroup = false; // If true, the next item will start a new grouplet 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++) {const item = items[index];+ const itemKind = ("kind" in item) ? item.kind : "";+if (!item) {continue;}// 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.- if ("kind" in item && item.kind === "header") {+ if (itemKind === "header") {if (multicolumn && !shouldResetGroup) {shouldStartNewGroup = true;}@@ -200,14 +203,18 @@ class ContextMenu {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"));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));shouldResetGroup = true;} else {- if ("kind" in item && item.kind === "custom") {+ if (itemKind === "custom") {// Custom menu item$group.append(this.createCustomMenuItem(item));} else {@@ -222,6 +229,9 @@ class ContextMenu {shouldResetGroup = false;};}++ prevItemKind = itemKind;+}}