Bug 844606 - Remove all selected entries while removing items from history. r=mano, a=lsblakk
authorGirish Sharma <scrapmachines@gmail.com>
Fri, 31 May 2013 11:26:13 +0530
changeset 142819 536e5dd3099890a1141fa4d41fc487c11a47d2a7
parent 142818 d79c9a26ad543368b819299e12be5a907bdaf3f3
child 142820 5d2958ada0477652ef3c0191ff969c547376e683
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmano, lsblakk
bugs844606
milestone23.0a2
Bug 844606 - Remove all selected entries while removing items from history. r=mano, a=lsblakk
browser/components/downloads/content/allDownloadsViewOverlay.js
--- a/browser/components/downloads/content/allDownloadsViewOverlay.js
+++ b/browser/components/downloads/content/allDownloadsViewOverlay.js
@@ -987,27 +987,29 @@ DownloadsPlacesView.prototype = {
     if (!aDocumentFragment) {
       this._ensureVisibleElementsAreActive();
       goUpdateCommand("downloadsCmd_clearDownloads");
     }
   },
 
   _removeElement: function DPV__removeElement(aElement) {
     // If the element was selected exclusively, select its next
-    // sibling first, if any.
-    if (aElement.nextSibling &&
+    // sibling first, if not, try for previous sibling, if any.
+    if ((aElement.nextSibling || aElement.previousSibling) &&
         this._richlistbox.selectedItems &&
-        this._richlistbox.selectedItems.length > 0 &&
+        this._richlistbox.selectedItems.length == 1 &&
         this._richlistbox.selectedItems[0] == aElement) {
-      this._richlistbox.selectItem(aElement.nextSibling);
+      this._richlistbox.selectItem(aElement.nextSibling ||
+                                   aElement.previousSibling);
     }
 
     if (this._lastSessionDownloadElement == aElement)
       this._lastSessionDownloadElement = aElement.previousSibling;
 
+    this._richlistbox.removeItemFromSelection(aElement);
     this._richlistbox.removeChild(aElement);
     this._ensureVisibleElementsAreActive();
     goUpdateCommand("downloadsCmd_clearDownloads");
   },
 
   _removeHistoryDownloadFromView:
   function DPV__removeHistoryDownloadFromView(aPlacesNode) {
     let downloadURI = aPlacesNode.uri;
@@ -1456,17 +1458,21 @@ DownloadsPlacesView.prototype = {
             .getService(Ci.nsIDownloadHistory)
             .removeAllDownloads();
         }
         // There may be no selection or focus change as a result
         // of these change, and we want the command updated immediately.
         goUpdateCommand("downloadsCmd_clearDownloads");
         break;
       default: {
-        let selectedElements = this._richlistbox.selectedItems;
+        // Slicing the array to get a freezed list of selected items. Otherwise,
+        // the selectedItems array is live and doCommand may alter the selection
+        // while we are trying to do one particular action, like removing items
+        // from history.
+        let selectedElements = this._richlistbox.selectedItems.slice();
         for (let element of selectedElements) {
           element._shell.doCommand(aCommand);
         }
       }
     }
   },
 
   onEvent: function() { },