Make it show which node triggered the event when right-clicking on the tree.

This commit is contained in:
SiriusXT
2025-05-06 14:55:17 +08:00
parent f0c735e4fc
commit 647a5c948c
3 changed files with 24 additions and 18 deletions

View File

@@ -10,6 +10,7 @@ interface ContextMenuOptions<T> {
items: MenuItem<T>[];
/** On mobile, if set to `true` then the context menu is shown near the element. If `false` (default), then the context menu is shown at the bottom of the screen. */
forcePositionOnMobile?: boolean;
onHide?: () => void;
}
interface MenuSeparatorItem {
@@ -36,7 +37,6 @@ export type ContextMenuEvent = PointerEvent | MouseEvent | JQuery.ContextMenuEve
class ContextMenu {
private $widget: JQuery<HTMLElement>;
private $cover: JQuery<HTMLElement>;
private dateContextMenuOpenedMs: number;
private options?: ContextMenuOptions<any>;
private isMobile: boolean;
@@ -44,7 +44,6 @@ class ContextMenu {
this.$widget = $("#context-menu-container");
this.$cover = $("#context-menu-cover");
this.$widget.addClass("dropend");
this.dateContextMenuOpenedMs = 0;
this.isMobile = utils.isMobile();
if (this.isMobile) {
@@ -76,8 +75,6 @@ class ContextMenu {
keyboardActionService.updateDisplayedShortcuts(this.$widget);
this.positionMenu();
this.dateContextMenuOpenedMs = Date.now();
}
positionMenu() {
@@ -220,18 +217,14 @@ class ContextMenu {
}
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
await timeout(100);
this.$widget.removeClass("show");
this.$cover.removeClass("show");
$("body").removeClass("context-menu-shown");
this.$widget.hide();
}
this.options?.onHide?.();
// 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
await timeout(100);
this.$widget.removeClass("show");
this.$cover.removeClass("show");
$("body").removeClass("context-menu-shown");
this.$widget.hide();
}
}