From ac9f34413048ddf5ec359157df327a59a9987e96 Mon Sep 17 00:00:00 2001 From: Adorian Doran Date: Wed, 20 Nov 2024 11:30:45 +0200 Subject: [PATCH] Retrigger the opening animation when repositioning menus that are already open --- src/public/app/menus/context_menu.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/public/app/menus/context_menu.js b/src/public/app/menus/context_menu.js index 16df2da28..073d9639f 100644 --- a/src/public/app/menus/context_menu.js +++ b/src/public/app/menus/context_menu.js @@ -12,6 +12,12 @@ class ContextMenu { async show(options) { this.options = options; + if (this.$widget.hasClass("show")) { + // The menu is already visible. Hide the menu then open it again + // at the new location to re-trigger the opening animation. + await this.hide(); + } + this.$widget.empty(); this.addItems(this.$widget, options.items); @@ -143,18 +149,26 @@ class ContextMenu { } } - hide() { + async hide() { // 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 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 - setTimeout(() => this.$widget.hide(), 100); + await timeout(100); + this.$widget.removeClass("show"); + this.$widget.hide() } } } +function timeout(ms) { + return new Promise((accept, reject) => { + setTimeout(accept, ms); + }); +} + const contextMenu = new ContextMenu(); export default contextMenu;