Bug 1641381 - composeKeyStatus.xhtml and oneRecipientStatus.xhtml table headers disappear. r=mkmelin a=wsmwk DONTBUILD
authorKai Engert <kaie@kuix.de>
Thu, 25 Jun 2020 23:32:15 +0200
changeset 39477 16ffc077a58d10cc44d72faa1d9fe322eedc36a9
parent 39476 a78e35148031051a5b2353ee389eae2508c79c84
child 39478 967707e1200c71b210cc9018dd10e8f773c33adf
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersmkmelin, wsmwk
bugs1641381
Bug 1641381 - composeKeyStatus.xhtml and oneRecipientStatus.xhtml table headers disappear. r=mkmelin a=wsmwk DONTBUILD Differential Revision: https://phabricator.services.mozilla.com/D81231
mail/extensions/openpgp/content/ui/composeKeyStatus.js
mail/extensions/openpgp/content/ui/oneRecipientStatus.js
--- a/mail/extensions/openpgp/content/ui/composeKeyStatus.js
+++ b/mail/extensions/openpgp/content/ui/composeKeyStatus.js
@@ -126,40 +126,43 @@ async function onLoad() {
       arrLen
     );
     addRecipients(gEmailAddresses, recList);
   }
 
   await setListEntries();
 }
 
-async function reload() {
+async function reloadAndReselect(selIndex = -1) {
   while (true) {
-    let child = gListBox.firstChild;
-    if (!child) {
+    let child = gListBox.lastChild;
+    // keep first child, which is the header
+    if (child == gListBox.firstChild) {
       break;
     }
     gListBox.removeChild(child);
   }
   gRowToEmail = [];
-  setListEntries();
+  await setListEntries();
+  gListBox.selectedIndex = selIndex;
 }
 
 function onSelectionChange(event) {
   gViewButton.disabled = !gListBox.selectedItems.length;
 }
 
 function viewSelectedEmail() {
-  if (gViewButton.disabled) {
+  let selIndex = gListBox.selectedIndex;
+  if (gViewButton.disabled || selIndex == -1) {
     return;
   }
-  let email = gRowToEmail[gListBox.selectedIndex];
+  let email = gRowToEmail[selIndex];
   window.openDialog(
     "chrome://openpgp/content/ui/oneRecipientStatus.xhtml",
     "",
     "chrome,modal,resizable,centerscreen",
     {
       email,
       keys: gMapAddressToKeyObjs.get(email),
     }
   );
-  reload();
+  reloadAndReselect(selIndex);
 }
--- a/mail/extensions/openpgp/content/ui/oneRecipientStatus.js
+++ b/mail/extensions/openpgp/content/ui/oneRecipientStatus.js
@@ -115,40 +115,39 @@ async function onLoad() {
     document.getElementById("intro"),
     "openpgp-intro",
     { key: gAddr }
   );
 
   await setListEntries(params.keys);
 }
 
-async function reload() {
+async function reloadAndSelect(selIndex = -1) {
   while (true) {
-    let child = gListBox.firstChild;
-    if (!child) {
+    let child = gListBox.lastChild;
+    // keep first child, which is the header
+    if (child == gListBox.firstChild) {
       break;
     }
     gListBox.removeChild(child);
   }
   gRowToKey = [];
-  setListEntries();
+  await setListEntries();
+  gListBox.selectedIndex = selIndex;
 }
 
 function onSelectionChange(event) {
   let haveSelection = gListBox.selectedItems.length;
   gViewButton.disabled = !haveSelection;
 }
 
 function viewSelectedKey() {
-  if (gViewButton.disabled) {
+  let selIndex = gListBox.selectedIndex;
+  if (gViewButton.disabled || selIndex == -1) {
     return;
   }
-  EnigmailWindows.openKeyDetails(
-    window,
-    gRowToKey[gListBox.selectedIndex],
-    false
-  );
-  reload();
+  EnigmailWindows.openKeyDetails(window, gRowToKey[selIndex], false);
+  reloadAndSelect(selIndex);
 }
 
 async function discoverKey() {
-  KeyLookupHelper.lookupAndImportByEmail(window, gAddr, true, reload);
+  KeyLookupHelper.lookupAndImportByEmail(window, gAddr, true, reloadAndSelect);
 }