Commit 6aa4fefa for codemirror.net

commit 6aa4fefafadfa786d3d2ac7d7ad5757968cdf494
Author: Marijn Haverbeke <marijn@haverbeke.nl>
Date:   Tue Jan 12 09:55:29 2021 +0100

    [brace-fold addon] Pick first opening token on a given line

    Closes #6560

diff --git a/addon/fold/brace-fold.js b/addon/fold/brace-fold.js
index 654d1fb6..79a331cf 100644
--- a/addon/fold/brace-fold.js
+++ b/addon/fold/brace-fold.js
@@ -31,13 +31,16 @@ CodeMirror.registerHelper("fold", "brace", function(cm, start) {
     }
   }

-  var startToken = "{", endToken = "}", startCh = findOpening("{");
-  if (startCh == null) {
-    startToken = "[", endToken = "]";
-    startCh = findOpening("[");
+  var startBrace = findOpening("{"), startBracket = findOpening("[")
+  var startToken, endToken, startCh
+  if (startBrace != null && (startBracket == null || startBracket > startBrace)) {
+    startCh = startBrace; startToken = "{"; endToken = "}"
+  } else if (startBracket != null) {
+    startCh = startBracket; startToken = "["; endToken = "]"
+  } else {
+    return
   }

-  if (startCh == null) return;
   var count = 1, lastLine = cm.lastLine(), end, endCh;
   outer: for (var i = line; i <= lastLine; ++i) {
     var text = cm.getLine(i), pos = i == line ? startCh : 0;