Bug 1575046 - Improve adding lists of addresses into mailing list dialogs. r=mkmelin a=jorgk
authorPaul Morris <paul@thunderbird.net>
Fri, 30 Aug 2019 08:54:12 +0200
changeset 35805 ffe571b2644faf2086a661696dedb42a6b2385ea
parent 35804 1f74906fee2f0980ec552146596f5bee261fb4d2
child 35806 13b18028d225a6d82bff99852e0f2147449dae56
push id28
push usermozilla@jorgk.com
push dateThu, 12 Sep 2019 17:56:37 +0000
treeherdercomm-esr68@bfd115c413ff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, jorgk
bugs1575046
Bug 1575046 - Improve adding lists of addresses into mailing list dialogs. r=mkmelin a=jorgk Separate comma-separated lists of addresses into separate rows, one address per row.
mail/components/compose/content/addressingWidgetOverlay.js
mailnews/addrbook/content/abMailListDialog.js
--- a/mail/components/compose/content/addressingWidgetOverlay.js
+++ b/mail/components/compose/content/addressingWidgetOverlay.js
@@ -779,21 +779,66 @@ function awRecipientOnFocus(inputElement
  * in the Address Book Mailing List dialogs.
  *
  * @param event       The DOM keypress event
  * @param element     The element that triggered the keypress event
  */
 function awAbRecipientKeyPress(event, element) {
   // Only add new row when enter was hit (not for tab/autocomplete select).
   if (event.key == "Enter") {
-    // Prevent dialogs from closing.
-    if (element.value != "") {
+    let inputElement = element;
+
+    if (element.value) {
+      // Prevent the dialog from closing.
       event.preventDefault();
+
+      let originalRow = awGetRowByInputElement(element);
+      let row;
+      let addresses = MailServices.headerParser
+                                  .makeFromDisplayAddress(element.value);
+
+      if (addresses.length > 1) {
+        // Collect any existing addresses from the following rows so we don't
+        // simply overwrite them.
+        row = originalRow + 1;
+        inputElement = awGetInputElement(row);
+
+        while (inputElement) {
+          if (inputElement.value) {
+            addresses.push(inputElement.value);
+            inputElement.value = "";
+          }
+          row += 1;
+          inputElement = awGetInputElement(row);
+        }
+      }
+
+      // Insert the addresses, adding new rows if needed.
+      row = originalRow;
+      let needNewRows = false;
+
+      for (let address of addresses) {
+        if (needNewRows) {
+          inputElement = awAppendNewRow(false);
+        } else {
+          inputElement = awGetInputElement(row);
+          if (!inputElement) {
+            needNewRows = true;
+            inputElement = awAppendNewRow(false);
+          }
+        }
+
+        if (inputElement) {
+          inputElement.value = address;
+        }
+        row += 1;
+      }
     }
-    awReturnHit(element);
+
+    awReturnHit(inputElement);
   }
 }
 
 /**
  * Handles keypress events for the email address inputs (that auto-fill)
  * in the Message Compose window.
  *
  * @param event       The DOM keypress event
--- a/mailnews/addrbook/content/abMailListDialog.js
+++ b/mailnews/addrbook/content/abMailListDialog.js
@@ -364,42 +364,50 @@ function awInputChanged(inputElement) {
 }
 
 function awInputElementName() {
   if (inputElementType == "")
       inputElementType = document.getElementById("addressCol1#1").localName;
   return inputElementType;
 }
 
+/**
+ * Append a new row.
+ *
+ * @param {boolean} setFocus  Whether to set the focus on the new row.
+ * @return {Element?}         The input element from the new row.
+ */
 function awAppendNewRow(setFocus) {
-  var body = document.getElementById("addressingWidget");
-  var listitem1 = awGetListItem(1);
+  let body = document.getElementById("addressingWidget");
+  let listitem1 = awGetListItem(1);
+  let input;
 
   if (body && listitem1) {
-    var nextDummy = awGetNextDummyRow();
-    var newNode = listitem1.cloneNode(true);
+    let nextDummy = awGetNextDummyRow();
+    let newNode = listitem1.cloneNode(true);
     if (nextDummy)
       body.replaceChild(newNode, nextDummy);
     else
       body.appendChild(newNode);
 
     top.MAX_RECIPIENTS++;
 
-    var input = newNode.getElementsByTagName(awInputElementName());
+    input = newNode.getElementsByTagName(awInputElementName());
     if (input && input.length == 1) {
       input[0].setAttribute("value", "");
       input[0].setAttribute("id", "addressCol1#" + top.MAX_RECIPIENTS);
 
       if (input[0].getAttribute("focused") != "")
         input[0].removeAttribute("focused");
     }
     // Focus the new input widget.
     if (setFocus && input)
       awSetFocusTo(input[0]);
   }
+  return input ? input[0] : null;
 }
 
 
 // functions for accessing the elements in the addressing widget
 
 function awGetInputElement(row) {
   return document.getElementById("addressCol1#" + row);
 }