Bug 1560751 - fix AB selection forgetting last selected AB in contacts sidebar. r=mkmelin
authorAlessandro Castellani <alessandro@thunderbird.net>
Tue, 25 Jun 2019 22:19:30 +0200
changeset 35950 4aed62fba5e7c54c0f66cdcdedd5ab917bd1d7d4
parent 35949 d04da3816b8e83bb9816322b5eb980e671ca704f
child 35951 3004cd1a0a75432d7e04592580a8a7511f38dab5
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersmkmelin
bugs1560751
Bug 1560751 - fix AB selection forgetting last selected AB in contacts sidebar. r=mkmelin
mail/components/addrbook/content/menulist-addrbooks.js
--- a/mail/components/addrbook/content/menulist-addrbooks.js
+++ b/mail/components/addrbook/content/menulist-addrbooks.js
@@ -90,17 +90,17 @@ customElements.whenDefined("menulist").t
     }
 
     disconnectedCallback() {
       super.disconnectedCallback();
 
       MailServices.ab.removeAddressBookListener(this.addressBookListener);
     }
 
-    _rebuild(aSelectValue) {
+    _rebuild() {
       // Init the address book cache.
       this._directories.length = 0;
       let directories = MailServices.ab.directories;
 
       while (directories && directories.hasMoreElements()) {
         let ab = directories.getNext();
         if ((ab instanceof Ci.nsIAbDirectory) && this._matches(ab)) {
           this._directories.push(ab);
@@ -163,20 +163,19 @@ customElements.whenDefined("menulist").t
           listItem.setAttribute("IsRemote", "true");
         }
         if (ab.isSecure) {
           listItem.setAttribute("IsSecure", "true");
         }
       }
 
       // Attempt to select the persisted or otherwise first directory.
-      this.value = aSelectValue;
-      if (!this.selectedItem && this.menupopup.hasChildNodes()) {
-        this.selectedIndex = 0;
-      }
+      this.selectedIndex = this._directories.findIndex((d) => {
+        return d && d.URI == this._value;
+      });
     }
 
     _teardown() {
       // Empty out anything in the list.
       while (this.menupopup && this.menupopup.hasChildNodes()) {
         this.menupopup.lastChild.remove();
       }
     }