Retrigger the opening animation when repositioning menus that are already open

This commit is contained in:
Adorian Doran 2024-11-20 11:30:45 +02:00
parent 2b432dd4f7
commit ac9f344130

View File

@ -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;