mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
fix(mobile): relayout would sometimes hide the context menu
This commit is contained in:
@@ -32,25 +32,24 @@ export type MenuHandler<T extends CommandNames> = (item: MenuCommandItem<T>, e:
|
||||
|
||||
class ContextMenu {
|
||||
|
||||
private $widget!: JQuery<HTMLElement>;
|
||||
private $widget: JQuery<HTMLElement>;
|
||||
private $cover: JQuery<HTMLElement>;
|
||||
private dateContextMenuOpenedMs: number;
|
||||
private options?: ContextMenuOptions<any>;
|
||||
private isMobile: boolean;
|
||||
|
||||
constructor() {
|
||||
this.$widget = $("#context-menu-container");
|
||||
this.$cover = $("#context-menu-cover");
|
||||
this.$widget.addClass("dropend");
|
||||
this.dateContextMenuOpenedMs = 0;
|
||||
this.isMobile = utils.isMobile();
|
||||
|
||||
$(document).on('click', (e) => {
|
||||
if (this.isMobile && $(e.target).closest("#context-menu-container").length) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Hide from ", e.target);
|
||||
this.hide();
|
||||
});
|
||||
if (this.isMobile) {
|
||||
this.$cover.on("click", this.hide);
|
||||
} else {
|
||||
$(document).on('click', (e) => this.hide);
|
||||
}
|
||||
}
|
||||
|
||||
async show<T extends CommandNames>(options: ContextMenuOptions<T>) {
|
||||
@@ -62,6 +61,8 @@ class ContextMenu {
|
||||
await this.hide();
|
||||
}
|
||||
|
||||
this.$cover.addClass("show");
|
||||
|
||||
this.$widget.empty();
|
||||
|
||||
this.addItems(this.$widget, options.items);
|
||||
@@ -223,7 +224,8 @@ class ContextMenu {
|
||||
// see https://github.com/zadam/trilium/pull/3805 for details
|
||||
await timeout(100);
|
||||
this.$widget.removeClass("show");
|
||||
this.$widget.hide()
|
||||
this.$cover.removeClass("show");
|
||||
this.$widget.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user