]> source.dussan.org Git - vaadin-framework.git/commitdiff
Keep block order when unnesting (#10309) 80/380/1
authorHenri Sara <hesara@vaadin.com>
Mon, 26 Nov 2012 10:36:46 +0000 (12:36 +0200)
committerHenri Sara <hesara@vaadin.com>
Mon, 26 Nov 2012 10:37:37 +0000 (12:37 +0200)
Change-Id: I5a7e6b74a55176799e85c943a128d9aab0db0876

theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
theme-compiler/src/com/vaadin/sass/internal/visitor/BlockNodeHandler.java
theme-compiler/tests/resources/css/nesting.css
theme-compiler/tests/resources/scss/nesting.scss
theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Nesting.java

index af061d8e959935ca2efe3806b7182c3d5aebb658..2a5d617a6b6a397996fe5fadc73ef21d12561d6c 100644 (file)
@@ -235,9 +235,14 @@ public class ScssStylesheet extends Node {
         variables.clear();
         variables.putAll(variableScope);
 
+        // clean up insert point so that processing of the next block will
+        // insert after that block
+        lastNodeAdded.remove(originalParent);
+
         // has the node been removed from its parent?
         if (originalParent != null) {
-            return !originalParent.getChildren().contains(node);
+            boolean removed = !originalParent.getChildren().contains(node);
+            return removed;
         } else {
             return false;
         }
index cb736ba5588892f22b21adf9681d19417660e3af..fc34e32f7a77f2c3357196709398800e0781fc38 100644 (file)
@@ -98,14 +98,15 @@ public class BlockNodeHandler {
         }
         node.setSelectorList(newList);
         Node oldParent = node.getParentNode();
+
         HashMap<Node, Node> lastNodeAdded = ScssStylesheet.getLastNodeAdded();
-        if (lastNodeAdded.get(oldParent) != null) {
-            oldParent.getParentNode().appendChild(node,
-                    lastNodeAdded.get(oldParent));
-        } else {
-            oldParent.getParentNode().appendChild(node, oldParent);
+        Node lastAdded = lastNodeAdded.get(oldParent.getParentNode());
+        if (lastAdded == null) {
+            lastAdded = oldParent;
         }
 
-        lastNodeAdded.put(oldParent, node);
+        oldParent.getParentNode().appendChild(node, lastAdded);
+
+        lastNodeAdded.put(oldParent.getParentNode(), node);
     }
 }
index b3861a013161b56ff319e94b8dbda6b2f88035d4..e1cdf3a57994baae661ce156e30f3673780d5fe8 100644 (file)
 
 .main .second.third .fourth {
        color: black;
+}
+
+.root .first-block .nested {
+       order: first;
+}
+
+.root .last-block {
+       order: last;
 }
\ No newline at end of file
index 0336c9e86dd60af404155aa7c201153f50c64dfa..1fefe0dde052b216b488eaddcc796ed4d7b6c5ca 100644 (file)
       color: black;
     }
   }
+}
+
+.root {
+       .first-block {
+               .nested {
+                       order: first;
+               }
+       }
+       
+       .last-block {
+               order: last;
+       }
 }
\ No newline at end of file
index 109182f6085d3ea497ce161ad19d715063b8531b..bdc6e63391bafe564a697383f9ab9594cc7f6b97 100644 (file)
@@ -42,7 +42,7 @@ public class Nesting extends AbstractTestBase {
         parser.setDocumentHandler(handler);
         parser.parseStyleSheet(getClass().getResource(scss).getPath());
         ScssStylesheet root = handler.getStyleSheet();
-        Assert.assertEquals(5, root.getChildren().size());
+        Assert.assertEquals(6, root.getChildren().size());
 
         BlockNode blockNode0 = (BlockNode) root.getChildren().get(0);
         Assert.assertEquals(2, blockNode0.getChildren().size());
@@ -78,6 +78,8 @@ public class Nesting extends AbstractTestBase {
         BlockNode nestednestedBlockInBlock4 = (BlockNode) nestedBlockInBlock3
                 .getChildren().get(1);
         Assert.assertEquals(1, nestednestedBlockInBlock4.getChildren().size());
+
+        // the parsing of the last block is not checked in detail
     }
 
     @Test