Bug 1066558 - Cant collapse a tree in web IDE, after expanding it; r=bgrins
authorManu Jain <manu.jain13@gmail.com>
Wed, 08 Oct 2014 15:49:48 -0700
changeset 209656 628001a7e7a7cd60d6b68f23d48d6ff1fa349760
parent 209655 a633be151fa77f0591b4f3c09a609177e569cadc
child 209657 9fe8432ce02ec509a9dfd50660f5ba9eb6d668ff
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbgrins
bugs1066558
milestone35.0a1
Bug 1066558 - Cant collapse a tree in web IDE, after expanding it; r=bgrins
browser/devtools/projecteditor/lib/tree.js
browser/devtools/projecteditor/test/browser_projecteditor_tree_selection_01.js
--- a/browser/devtools/projecteditor/lib/tree.js
+++ b/browser/devtools/projecteditor/lib/tree.js
@@ -64,34 +64,40 @@ var ResourceContainer = Class({
     }, false);
 
     this.children = doc.createElementNS(HTML_NS, "ul");
     this.children.classList.add("children");
 
     this.elt.appendChild(this.children);
 
     this.line.addEventListener("click", (evt) => {
-      if (!this.selected) {
-        this.select();
-        this.expanded = true;
-        evt.stopPropagation();
-      }
+      this.select();
+      this.toggleExpansion();
+      evt.stopPropagation();
     }, false);
     this.expander.addEventListener("click", (evt) => {
-      this.expanded = !this.expanded;
+      this.toggleExpansion();
       this.select();
       evt.stopPropagation();
     }, true);
 
     if (!this.resource.isRoot) {
       this.expanded = false;
     }
     this.update();
   },
 
+  toggleExpansion: function() {
+    if (!this.resource.isRoot) {
+      this.expanded = !this.expanded;
+    } else {
+      this.expanded = true;
+    }
+  },
+
   destroy: function() {
     this.elt.remove();
     this.expander.remove();
     this.highlighter.remove();
     this.children.remove();
     this.label.remove();
     this.elt = this.expander = this.highlighter = this.children = this.label = null;
   },
--- a/browser/devtools/projecteditor/test/browser_projecteditor_tree_selection_01.js
+++ b/browser/devtools/projecteditor/test/browser_projecteditor_tree_selection_01.js
@@ -34,20 +34,26 @@ let test = asyncTest(function*() {
 
 function selectFileFirstLoad(projecteditor, resource) {
   ok (resource && resource.path, "A valid resource has been passed in for selection " + (resource && resource.path));
   projecteditor.projectTree.selectResource(resource);
   let container = projecteditor.projectTree.getViewContainer(resource);
 
   if (resource.isRoot) {
     ok (container.expanded, "The root directory is expanded by default.");
+    container.line.click();
+    ok (container.expanded, "Clicking on the line does not toggles expansion.");
     return;
   }
   if (resource.isDir) {
     ok (!container.expanded, "A directory is not expanded by default.");
+    container.line.click();
+    ok (container.expanded, "Clicking on the line toggles expansion.");
+    container.line.click();
+    ok (!container.expanded, "Clicking on the line toggles expansion.");
     return;
   }
 
   let [editorCreated, editorLoaded, editorActivated] = yield promise.all([
     onceEditorCreated(projecteditor),
     onceEditorLoad(projecteditor),
     onceEditorActivated(projecteditor)
   ]);