Bug 1615917 - Allow incremental selection of recipient pills with Ctrl+A. ui-r=aleca, r=aleca
authorThomas Duellmann <bugzilla2007@duellmann24.net>
Tue, 18 Feb 2020 11:33:49 +0200
changeset 37367 c510f2acfb18914b5102a74bd1ba66a59bd2c5e6
parent 37366 7f802938f14d5d20330dd34c93a6ed3460e26882
child 37368 3b6df2137d8f7cec3f9e30841155d3dca49831b6
push id2566
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:20:31 +0000
treeherdercomm-beta@a352facfa0a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaleca, aleca
bugs1615917
Bug 1615917 - Allow incremental selection of recipient pills with Ctrl+A. ui-r=aleca, r=aleca First Ctrl+A to select all in same field, second Ctrl+A to select all pills in all fields.
mail/base/content/mailWidgets.js
--- a/mail/base/content/mailWidgets.js
+++ b/mail/base/content/mailWidgets.js
@@ -2340,19 +2340,33 @@
           if (event.shiftKey) {
             this.moveFocusToPreviousElement(pill);
             return;
           }
           pill.rowInput.focus();
           break;
 
         case "a":
-          if (event.ctrlKey || event.metaKey) {
+          if (!(event.ctrlKey || event.metaKey) || event.repeat) {
+            // Bail out if it's not Ctrl+A or Cmd+A or if repeated keypress.
+            break;
+          }
+          if (
+            pill
+              .closest(".address-container")
+              .querySelector("mail-address-pill:not([selected])")
+          ) {
+            // For non-repeated Ctrl+A, if there's at least one unselected pill,
+            // first select all pills of the same .address-container.
             this.selectPills(pill);
+            break;
           }
+          // For non-repeated Ctrl+A, if pills in same container are already
+          // selected, select all pills of the entire <mail-recipients-area>.
+          this.selectAllPills(pill);
           break;
 
         case "c":
           if (event.ctrlKey || event.metaKey) {
             copyEmailNewsAddress(pill);
           }
           break;
 
@@ -2504,58 +2518,69 @@
      *
      * @param {XULElement} pill - The mail-address-pill element.
      */
     setFocusOnFirstPill(pill) {
       pill.closest(".address-container").firstElementChild.focus();
     }
 
     /**
+     * Select all the pills from the mail-recipients-area element.
+     *
+     * @param {Element} pill - The focused mail-address-pill element.
+     */
+    selectAllPills(pill) {
+      for (let item of this.getAllPills(pill)) {
+        item.setAttribute("selected", "selected");
+      }
+    }
+
+    /**
      * Select all the pills from the same .address-container.
      *
-     * @param {XULElement} pill - The mail-address-pill element.
+     * @param {Element} pill - The focused <mail-address-pill> element.
      */
     selectPills(pill) {
       for (let item of this.getSiblingPills(pill)) {
         item.setAttribute("selected", "selected");
       }
     }
 
     /**
      * Return all the pills from the same .address-container.
      *
-     * @param {XULElement} pill - The mail-address-pill element.
-     * @return {Array} Array of mail-address-pill elements.
+     * @param {Element} pill - The focused <mail-address-pill> element.
+     * @return {NodeList} NodeList of <mail-address-pill> elements in same field.
      */
     getSiblingPills(pill) {
       return pill
         .closest(".address-container")
         .querySelectorAll("mail-address-pill");
     }
 
     /**
-     * Return all the pills currently available in the address area.
+     * Return all the pills currently available in the <mail-recipients-area>.
      *
-     * @return {Array} Array of mail-address-pill elements.
+     * @return {NodeList} NodeList of all <mail-address-pill> elements.
      */
     getAllPills() {
       return this.querySelectorAll("mail-address-pill");
     }
 
     /**
-     * Return all the selected pills currently available in the address area.
+     * Return all currently selected pills in the <mail-recipients-area>.
      *
-     * @return {Array} Array of selected mail-address-pill elements.
+     * @return {NodeList} NodeList of all selected <mail-address-pill> elements.
      */
     getAllSelectedPills() {
       return this.querySelectorAll("mail-address-pill[selected]");
     }
 
     /**
-     * Check if any pill in the addressing area is selected.
+     * Check if any pill in the <mail-recipients-area> is selected.
      *
      * @return {boolean} true if any pill is selected.
      */
     hasSelectedPills() {
       return Boolean(this.querySelector("mail-address-pill[selected]"));
     }
 
     /**