diff --git a/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/AbstractJFlexCTokenMaker.java b/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/AbstractJFlexCTokenMaker.java index 9879d0c09..1ebf5052a 100755 --- a/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/AbstractJFlexCTokenMaker.java +++ b/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/AbstractJFlexCTokenMaker.java @@ -176,7 +176,7 @@ private boolean appearsNested(RSyntaxTextArea textArea, while (line -1 ? nonWhitespacePos : end); + textArea.replaceSelection(sb.toString()); - // Must do it after everything else, as the "smart indent" - // calculation depends on the previous line's state - // AFTER the Enter press (stuff may have been moved down). - if (sta.getShouldIndentNextLine(lineNum)) { - sta.replaceSelection("\t"); - } + // Must do it after everything else, as the "smart indent" + // calculation depends on the previous line's state + // AFTER the Enter press (stuff may have been moved down). + if (textArea.getShouldIndentNextLine(lineNum)) { + textArea.replaceSelection("\t"); + } - possiblyCloseCurlyBrace(sta, leadingWS); + possiblyCloseCurlyBrace(textArea, leadingWS); + } - } catch (BadLocationException ble) { // Never happens - sta.replaceSelection("\n"); - ble.printStackTrace(); + private static boolean isAllWhitespace(String str, int from, int to) { + for (int i = from; i < to; i++) { + if (!Character.isWhitespace(str.charAt(i))) { + return false; + } } - + return true; } private void possiblyCloseCurlyBrace(RSyntaxTextArea textArea, diff --git a/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxUtilities.java b/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxUtilities.java index 4e0f3e992..56bb7c483 100755 --- a/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxUtilities.java +++ b/RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxUtilities.java @@ -251,11 +251,25 @@ public static Color getHyperlinkForeground() { * * @param text The String to check. * @return The leading whitespace. + * @see #getLeadingWhitespace(String, int) * @see #getLeadingWhitespace(Document, int) */ public static String getLeadingWhitespace(String text) { + return getLeadingWhitespace(text, Integer.MAX_VALUE); + } + + + /** + * Returns the leading whitespace of a string. + * + * @param text The String to check. + * @param upTo Stops checking at the specified offset. + * @return The leading whitespace. + * @see #getLeadingWhitespace(String) + */ + public static String getLeadingWhitespace(String text, int upTo) { int count = 0; - int len = text.length(); + int len = Math.min(text.length(), upTo); while (count