From 08ad954e9c7e54cacf2ed4ab16e117fde0b6d792 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 28 Dec 2024 10:04:53 +0200 Subject: [PATCH] fix(mobile): menu hiding when collapsing submenu --- src/public/app/menus/context_menu.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/public/app/menus/context_menu.ts b/src/public/app/menus/context_menu.ts index 607025701..54140d9ea 100644 --- a/src/public/app/menus/context_menu.ts +++ b/src/public/app/menus/context_menu.ts @@ -48,6 +48,7 @@ class ContextMenu { return; } + console.log("Hide from ", e.target); this.hide(); }); } @@ -168,10 +169,13 @@ class ContextMenu { } if (this.isMobile && "items" in item && item.items) { - $(e.target) - .closest(".dropdown-item") - .find("ul.dropdown-menu") - .toggleClass("show"); + // We run using a timeout to avoid the layout change during event handling, which would trigger the menu to be hidden sometimes. + setTimeout(() => { + $(e.target) + .closest(".dropdown-item") + .find("ul.dropdown-menu") + .toggleClass("show"); + }, 0); e.preventDefault(); return false; } @@ -213,6 +217,7 @@ class ContextMenu { // this date checking comes from change in FF66 - https://github.com/zadam/trilium/issues/468 // "contextmenu" event also triggers "click" event which depending on the timing can close the just opened context menu // we might filter out right clicks, but then it's better if even right clicks close the context menu + console.warn(new Error()); if (Date.now() - this.dateContextMenuOpenedMs > 300) { // seems like if we hide the menu immediately, some clicks can get propagated to the underlying component // see https://github.com/zadam/trilium/pull/3805 for details