diff -r 688a820889a5 javascript.editing/src/org/netbeans/modules/javascript/editing/JsFormatter.java --- a/javascript.editing/src/org/netbeans/modules/javascript/editing/JsFormatter.java Thu Oct 16 22:45:51 2008 +0200 +++ b/javascript.editing/src/org/netbeans/modules/javascript/editing/JsFormatter.java Thu Oct 16 18:19:43 2008 -0700 @@ -367,7 +367,7 @@ } @SuppressWarnings("unchecked") - private int getTokenBalance(TokenSequence ts, BaseDocument doc, int begin, int end, boolean includeKeywords, boolean indentOnly) { + private int getTokenBalance(TokenSequence ts, BaseDocument doc, final int begin, int end, boolean includeKeywords, boolean indentOnly) { int balance = 0; if (ts == null) { @@ -406,7 +406,7 @@ if (embeddedJavaScript && last < end) { // We're not done yet... find the next section... TokenSequence ets = LexUtilities.getNextJsTokenSequence(doc, last+1, end); - if (ets != null) { + if (ets != null && ets.offset() > begin) { return balance + getTokenBalance(ets, doc, ets.offset(), end, includeKeywords, indentOnly); } }