fix closing of context menu on FF66, closes #468

This commit is contained in:
zadam 2019-03-28 20:54:17 +01:00
parent 946dae72d9
commit 3c56d29fca
2 changed files with 19 additions and 2 deletions

View File

@ -1,5 +1,7 @@
const $contextMenuContainer = $("#context-menu-container"); const $contextMenuContainer = $("#context-menu-container");
let dateContextMenuOpenedMs = 0;
function initContextMenu(event, contextMenuItems, selectContextMenuItem) { function initContextMenu(event, contextMenuItems, selectContextMenuItem) {
event.stopPropagation(); event.stopPropagation();
@ -73,6 +75,8 @@ function initContextMenu(event, contextMenuItems, selectContextMenuItem) {
top = event.pageY - 10; top = event.pageY - 10;
} }
dateContextMenuOpenedMs = Date.now();
$contextMenuContainer.css({ $contextMenuContainer.css({
display: "block", display: "block",
top: top, top: top,
@ -80,8 +84,18 @@ function initContextMenu(event, contextMenuItems, selectContextMenuItem) {
}).addClass("show"); }).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 { export default {
initContextMenu initContextMenu,
hideContextMenu
} }

View File

@ -417,6 +417,9 @@ function initFancyTree(tree) {
const node = data.node; const node = data.node;
const noteId = node.data.noteId; const noteId = node.data.noteId;
// click event won't propagate so let's close context menu manually
contextMenuWidget.hideContextMenu();
setCurrentNotePathToHash(node); setCurrentNotePathToHash(node);
noteDetailService.switchToNote(noteId); noteDetailService.switchToNote(noteId);