Skip to content

Build your personal knowledge base with Trilium Notes

Retrigger the opening animation when repositioning menus that are already open

Adorian Doranac9f34413048
diff --git a/src/public/app/menus/context_menu.js b/src/public/app/menus/context_menu.js
index 16df2da282..073d9639f5 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;