Use standard context menu in HTML input boxes

This fixes the context menu for text fields in the new React-based tags
box.
This commit is contained in:
Dan Stillman 2019-11-30 00:41:29 -07:00
parent 0fb9548326
commit 76f1f9cae6
2 changed files with 28 additions and 2 deletions

View file

@ -780,5 +780,30 @@ function openUILinkIn(url) {
ZoteroPane.loadURI(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("load", function(e) { ZoteroStandalone.onLoad(e); }, false);
window.addEventListener("unload", function(e) { ZoteroStandalone.onUnload(e); }, false); window.addEventListener("unload", function(e) { ZoteroStandalone.onUnload(e); }, false);

View file

@ -83,7 +83,7 @@
</keyset> </keyset>
<keyset id="editMenuKeys"/> <keyset id="editMenuKeys"/>
<popup id="contentAreaContextMenu"> <menupopup id="contentAreaContextMenu">
<menuitem id="context-undo" <menuitem id="context-undo"
label="&undoCmd.label;" label="&undoCmd.label;"
accesskey="&undoCmd.accesskey;" accesskey="&undoCmd.accesskey;"
@ -110,7 +110,8 @@
label="&selectAllCmd.label;" label="&selectAllCmd.label;"
accesskey="&selectAllCmd.accesskey;" accesskey="&selectAllCmd.accesskey;"
command="cmd_selectAll"/> command="cmd_selectAll"/>
</popup> </menupopup>
<toolbox id="navigator-toolbox" class="toolbox-top" mode="icons" defaultmode="icons"> <toolbox id="navigator-toolbox" class="toolbox-top" mode="icons" defaultmode="icons">
<!-- Menu --> <!-- Menu -->
<toolbar type="menubar" id="toolbar-menubar" class="chromeclass-menubar" customizable="true" <toolbar type="menubar" id="toolbar-menubar" class="chromeclass-menubar" customizable="true"