Bug 1593629 - Restore adding named anchors to context menu for links. r=mkmelin a=jorgk
--- a/mail/components/compose/content/dialogs/EdDialogCommon.js
+++ b/mail/components/compose/content/dialogs/EdDialogCommon.js
@@ -567,17 +567,16 @@ var NotAnInlineParent = [
"tbody",
"tfoot",
"thead",
"tr",
"ul",
];
function FillLinkMenulist(linkMenulist, headingsArray) {
- var menupopup = linkMenulist.firstElementChild;
var editor = GetCurrentEditor();
try {
var treeWalker = editor.document.createTreeWalker(
editor.document,
1,
null,
true
);
@@ -641,51 +640,62 @@ function FillLinkMenulist(linkMenulist,
anchor += "_";
}
anchorList.push({ anchor, sortkey: anchor.toLowerCase() });
anchorMap[anchor] = true;
// Save nodes in an array so we can create anchor node under it later
headingsArray[anchor] = heading;
}
+ let menuItems = [];
if (anchorList.length) {
// case insensitive sort
anchorList.sort((a, b) => {
if (a.sortkey < b.sortkey) {
return -1;
}
if (a.sortkey > b.sortkey) {
return 1;
}
return 0;
});
-
for (i = 0; i < anchorList.length; i++) {
- createMenuItem(menupopup, anchorList[i].anchor);
+ menuItems.push(createMenuItem(anchorList[i].anchor));
}
} else {
// Don't bother with named anchors in Mail.
if (editor && editor.flags & Ci.nsIPlaintextEditor.eEditorMailMask) {
- menupopup.remove();
linkMenulist.removeAttribute("enablehistory");
return;
}
- var item = createMenuItem(
- menupopup,
- GetString("NoNamedAnchorsOrHeadings")
- );
+ let item = createMenuItem(GetString("NoNamedAnchorsOrHeadings"));
item.setAttribute("disabled", "true");
+ menuItems.push(item);
}
+ window.addEventListener("contextmenu", event => {
+ if (document.getElementById("datalist-menuseparator")) {
+ return;
+ }
+ let menuseparator = document.createXULElement("menuseparator");
+ menuseparator.setAttribute("id", "datalist-menuseparator");
+ document.getElementById("textbox-contextmenu").appendChild(menuseparator);
+ for (let menuitem of menuItems) {
+ document.getElementById("textbox-contextmenu").appendChild(menuitem);
+ }
+ });
} catch (e) {}
}
-function createMenuItem(aMenuPopup, aLabel) {
+function createMenuItem(label) {
var menuitem = document.createXULElement("menuitem");
- menuitem.setAttribute("label", aLabel);
- aMenuPopup.appendChild(menuitem);
+ menuitem.setAttribute("label", label);
+ menuitem.addEventListener("click", event => {
+ gDialog.hrefInput.value = label;
+ ChangeLinkLocation();
+ });
return menuitem;
}
// Shared by Image and Link dialogs for the "Choose" button for links
function chooseLinkFile() {
GetLocalFileURL("html, img").then(fileURL => {
// Always try to relativize local file URLs
if (gHaveDocumentUrl) {