Skip to content

Build your personal knowledge base with Trilium Notes

fix closing of context menu on FF66, closes #468

zadam3c56d29fca16
diff --git a/src/public/javascripts/services/context_menu.js b/src/public/javascripts/services/context_menu.js
index 89d0cd5adf..7f9c6c95b6 100644
--- a/src/public/javascripts/services/context_menu.js
+++ b/src/public/javascripts/services/context_menu.js
@@ -1,5 +1,7 @@
const $contextMenuContainer = $("#context-menu-container");
+let dateContextMenuOpenedMs = 0;
+
function initContextMenu(event, contextMenuItems, selectContextMenuItem) {
event.stopPropagation();
@@ -73,6 +75,8 @@ function initContextMenu(event, contextMenuItems, selectContextMenuItem) {
top = event.pageY - 10;
}
+ dateContextMenuOpenedMs = Date.now();
+
$contextMenuContainer.css({
display: "block",
top: top,
@@ -80,8 +84,18 @@ function initContextMenu(event, contextMenuItems, selectContextMenuItem) {
}).addClass("show");
}
-$(document).click(() => $contextMenuContainer.hide());
+$(document).click(() => hideContextMenu());
+
+function hideContextMenu() {
+ // 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 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() - dateContextMenuOpenedMs > 300) {
+ $contextMenuContainer.hide();
+ }
+}
export default {
- initContextMenu
+ initContextMenu,
+ hideContextMenu
}
\ No newline at end of file
diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js
index 466a7b28f9..92f1e78553 100644
--- a/src/public/javascripts/services/tree.js
+++ b/src/public/javascripts/services/tree.js
@@ -417,6 +417,9 @@ function initFancyTree(tree) {
const node = data.node;
const noteId = node.data.noteId;
+ // click event won't propagate so let's close context menu manually
+ contextMenuWidget.hideContextMenu();
+
setCurrentNotePathToHash(node);
noteDetailService.switchToNote(noteId);