Bug 1394750 - Fix selected devtools panel when an Extension DevTools panel is unloaded. draft
authorLuca Greco <lgreco@mozilla.com>
Fri, 23 Mar 2018 00:46:27 +0100
changeset 771709 8f96572cb1ef61d0b6b1510f7481ffb36a91c443
parent 771708 ae30909884746de3b04b345b5490aa452632a71a
child 771710 0c7ee50d2c30874c082eb93247b36983ebed95c8
child 772690 ddfed3604d60d1466d6b967a619dc5df4125a6d5
child 776679 0cafd5ef71213e1b3bb66787ef6159f8ca421672
child 776689 11d9353f759411e47f737410079363a1b4178fde
child 776700 4fc71c382611166b130688e7fe137d76fae5f05f
push id103755
push userluca.greco@alcacoop.it
push dateFri, 23 Mar 2018 18:04:59 +0000
bugs1394750
milestone61.0a1
Bug 1394750 - Fix selected devtools panel when an Extension DevTools panel is unloaded. MozReview-Commit-ID: 25erR7FJEsY
devtools/client/framework/toolbox.js
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -1643,18 +1643,16 @@ Toolbox.prototype = {
     }
 
     if (!this.hasAdditionalTool(toolId)) {
       throw new Error("Tool definition not registered to this toolbox: " +
                       toolId);
     }
 
     this.additionalToolDefinitions.delete(toolId);
-    this.visibleAdditionalTools = this.visibleAdditionalTools
-                                      .filter(id => id !== toolId);
     this.unloadTool(toolId);
   },
 
   /**
    * Ensure the tool with the given id is loaded.
    *
    * @param {string} id
    *        The id of the tool to load.
@@ -2469,31 +2467,61 @@ Toolbox.prototype = {
 
     // Select another tool.
     if (this.currentToolId == toolId) {
       let index = this.panelDefinitions.findIndex(({id}) => id === toolId);
       let nextTool = this.panelDefinitions[index + 1];
       let previousTool = this.panelDefinitions[index - 1];
       let toolNameToSelect;
 
+      // If the toolId can't be found in the globally registered panel definitions
+      // Check if the tool was actually part of the additional tools created by
+      // a WebExtension.
+      if (index === -1) {
+        let additionalNextTool;
+        let additionalPrevtool;
+
+        let additionalToolIndex = this.visibleAdditionalTools
+                                      .findIndex(id => id === toolId);
+
+        if (additionalToolIndex >= 0) {
+          additionalNextTool = this.visibleAdditionalTools[additionalToolIndex + 1];
+          additionalPrevtool = this.visibleAdditionalTools[additionalToolIndex - 1];
+
+          if (!additionalPrevtool) {
+            previousTool = this.panelDefinitions[this.panelDefinitions.length - 1];
+          }
+        }
+
+        if (additionalNextTool) {
+          nextTool = additionalNextTool;
+        }
+
+        if (additionalPrevtool) {
+          previousTool = additionalPrevtool;
+        }
+      }
+
       if (nextTool) {
         toolNameToSelect = nextTool.id;
       }
       if (previousTool) {
         toolNameToSelect = previousTool.id;
       }
+
       if (toolNameToSelect) {
         this.selectTool(toolNameToSelect);
       }
     }
 
     // Remove this tool from the current panel definitions.
-    this.panelDefinitions = this.panelDefinitions.filter(({id}) => id !== toolId);
     this.visibleAdditionalTools = this.visibleAdditionalTools
                                       .filter(id => id !== toolId);
+    this.panelDefinitions = this.panelDefinitions.filter(({id}) => id !== toolId);
+
     this._combineAndSortPanelDefinitions();
 
     if (panel) {
       panel.remove();
     }
 
     if (this.hostType == Toolbox.HostType.WINDOW) {
       let doc = this.win.parent.document;