junichi11 closed pull request #626: donation2_merge:#240529: Fixing folding of 
empty {}
URL: https://github.com/apache/incubator-netbeans/pull/626
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsStructureScanner.java
 
b/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsStructureScanner.java
index bfcd21a2f1..cce0ea793f 100644
--- 
a/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsStructureScanner.java
+++ 
b/javascript2.editor/src/org/netbeans/modules/javascript2/editor/JsStructureScanner.java
@@ -335,8 +335,17 @@ public FoldingItem(String kind, int start) {
                         stack.add(new FoldingItem(kind, ts.offset()));
                     } else if (tokenId == JsTokenId.BRACKET_RIGHT_CURLY && 
!stack.isEmpty()) {
                         FoldingItem fromStack = stack.remove(stack.size() - 1);
-                        appendFold(folds, fromStack.kind, 
info.getSnapshot().getOriginalOffset(fromStack.start),
-                                
info.getSnapshot().getOriginalOffset(ts.offset() + 1));
+
+                        TokenId previousTokenId = null;
+                        if (ts.movePrevious()) {
+                            previousTokenId = ts.token().id();
+                            ts.moveNext();
+                        }
+                        
+                        if (previousTokenId != null && previousTokenId != 
JsTokenId.BRACKET_LEFT_CURLY) {
+                            appendFold(folds, fromStack.kind, 
info.getSnapshot().getOriginalOffset(fromStack.start),
+                                    
info.getSnapshot().getOriginalOffset(ts.offset() + 1));
+                        }
                     }
                 }
             }
diff --git 
a/javascript2.editor/test/unit/data/testfiles/coloring/czechChars.js.folds 
b/javascript2.editor/test/unit/data/testfiles/coloring/czechChars.js.folds
index 283b98b0ea..e904d5731d 100644
--- a/javascript2.editor/test/unit/data/testfiles/coloring/czechChars.js.folds
+++ b/javascript2.editor/test/unit/data/testfiles/coloring/czechChars.js.folds
@@ -22,7 +22,7 @@
 -         yearSuffix: ''};
 |     $.timepicker.setDefaults($.timepicker.regional['cs']);
 |     
-+     var test = {}
+|     var test = {}
 |     test["myProperty"] = 20;
 |     test.anotherProperty = test.myProperty;
 - });
diff --git 
a/javascript2.editor/test/unit/data/testfiles/structure/issue240529.js 
b/javascript2.editor/test/unit/data/testfiles/structure/issue240529.js
new file mode 100644
index 0000000000..87ae39b9ff
--- /dev/null
+++ b/javascript2.editor/test/unit/data/testfiles/structure/issue240529.js
@@ -0,0 +1,15 @@
+/**
+ * 
+ * @returns {undefined}
+ */
+function method1() {
+
+}
+
+/**
+ * 
+ * @returns {undefined}
+ */
+function method2(){}
+
+var test = {}
diff --git 
a/javascript2.editor/test/unit/data/testfiles/structure/issue240529.js.folds 
b/javascript2.editor/test/unit/data/testfiles/structure/issue240529.js.folds
new file mode 100644
index 0000000000..7a2ca10c47
--- /dev/null
+++ b/javascript2.editor/test/unit/data/testfiles/structure/issue240529.js.folds
@@ -0,0 +1,16 @@
++ /**
+|  * 
+|  * @returns {undefined}
+-  */
++ function method1() {
+| 
+- }
+  
++ /**
+|  * 
+|  * @returns {undefined}
+-  */
+  function method2(){}
+  
+  var test = {}
+  
diff --git 
a/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsStructureScannerTest.java
 
b/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsStructureScannerTest.java
index 711a8d5473..df3f4e10ea 100644
--- 
a/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsStructureScannerTest.java
+++ 
b/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsStructureScannerTest.java
@@ -76,6 +76,10 @@ public void testIssue228186() throws Exception {
         checkFolds("testfiles/structure/issue228186.js");
     }
 
+    public void testIssue240529() throws Exception {
+        checkFolds("testfiles/structure/issue240529.js");
+    }
+
     public void testSimpleMethodChain() throws Exception {
         
checkStructure("testfiles/completion/simpleMethodChain/methodChainSimple.js");
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to