From 76f1f9cae6f404f552ca9bc54e6d38e1b18e9458 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 30 Nov 2019 00:41:29 -0700 Subject: [PATCH] Use standard context menu in HTML input boxes This fixes the context menu for text fields in the new React-based tags box. --- .../content/zotero/standalone/standalone.js | 25 +++++++++++++++++++ .../content/zotero/standalone/standalone.xul | 5 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/standalone/standalone.js b/chrome/content/zotero/standalone/standalone.js index 761129c8a5..2ef4ed9e32 100644 --- a/chrome/content/zotero/standalone/standalone.js +++ b/chrome/content/zotero/standalone/standalone.js @@ -780,5 +780,30 @@ function openUILinkIn(url) { ZoteroPane.loadURI(url); } +// Support context menus on HTML text boxes +// +// Adapted from editMenuOverlay.js in Fx68 +window.addEventListener("contextmenu", e => { + const HTML_NS = "http://www.w3.org/1999/xhtml"; + let needsContextMenu = + e.target.ownerDocument == document && + !e.defaultPrevented && + e.target.parentNode.nodeName != "moz-input-box" && + ((["textarea", "input"].includes(e.target.localName) && + e.target.namespaceURI == HTML_NS) || + e.target.closest("search-textbox")); + + if (!needsContextMenu) { + return; + } + + let popup = document.getElementById("contentAreaContextMenu"); + popup.openPopupAtScreen(e.screenX, e.screenY, true); + // Don't show any other context menu at the same time. There can be a + // context menu from an ancestor too but we only want to show this one. + e.preventDefault(); +}); + + window.addEventListener("load", function(e) { ZoteroStandalone.onLoad(e); }, false); window.addEventListener("unload", function(e) { ZoteroStandalone.onUnload(e); }, false); \ No newline at end of file diff --git a/chrome/content/zotero/standalone/standalone.xul b/chrome/content/zotero/standalone/standalone.xul index ab9029778e..d6f748d1d4 100644 --- a/chrome/content/zotero/standalone/standalone.xul +++ b/chrome/content/zotero/standalone/standalone.xul @@ -83,7 +83,7 @@ - + - + +