mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-31 20:22:27 +08:00
Retrigger the opening animation when repositioning menus that are already open
This commit is contained in:
parent
2b432dd4f7
commit
ac9f344130
@ -12,6 +12,12 @@ class ContextMenu {
|
|||||||
async show(options) {
|
async show(options) {
|
||||||
this.options = 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.$widget.empty();
|
||||||
|
|
||||||
this.addItems(this.$widget, options.items);
|
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
|
// 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
|
// "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
|
// 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) {
|
if (Date.now() - this.dateContextMenuOpenedMs > 300) {
|
||||||
// seems like if we hide the menu immediately, some clicks can get propagated to the underlying component
|
// 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
|
// 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();
|
const contextMenu = new ContextMenu();
|
||||||
|
|
||||||
export default contextMenu;
|
export default contextMenu;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user