diff --git a/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp b/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp index 775b582ff6..ed2d9caa78 100644 --- a/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp +++ b/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp @@ -176,6 +176,24 @@ namespace CppUtils return String (line.getCharPointer(), endOfLeadingWS); } + static int getBraceCount (String::CharPointerType line) + { + int braces = 0; + + for (;;) + { + const juce_wchar c = line.getAndAdvance(); + + if (c == 0) break; + else if (c == '{') ++braces; + else if (c == '}') --braces; + else if (c == '/') { if (*line == '/') break; } + else if (c == '"' || c == '\'') { while (! (line.isEmpty() || line.getAndAdvance() == c)) {} } + } + + return braces; + } + static bool getIndentForCurrentBlock (CodeDocument::Position pos, String& whitespace) { int braceCount = 0; @@ -187,35 +205,12 @@ namespace CppUtils const String line (pos.getLineText()); const String trimmedLine (line.trimStart()); - String::CharPointerType l (trimmedLine.getCharPointer()); + braceCount += getBraceCount (trimmedLine.getCharPointer()); - for (;;) + if (braceCount > 0) { - const juce_wchar c = l.getAndAdvance(); - - if (c == 0) - break; - - if (c == '}') - ++braceCount; - - if (c == '{') - { - if (--braceCount < 0) - { - whitespace = getLeadingWhitespace (line); - return true; - } - } - - if (c == '"' || c == '\'') - { - while (! (l.isEmpty() || l.getAndAdvance() == c)) - {} - } - - if (c == '/' && *l == '/') - break; + whitespace = getLeadingWhitespace (line); + return true; } } @@ -254,11 +249,10 @@ void CppCodeEditorComponent::handleReturnKey() while (pos.getLineNumber() > 0) { pos = pos.movedByLines (-1); - const String leadingWhitespace (CppUtils::getLeadingWhitespace (pos.getLineText())); - if (leadingWhitespace.isNotEmpty()) + if (pos.getLineText().trimStart().isNotEmpty()) { - insertTextAtCaret (leadingWhitespace); + insertTextAtCaret (CppUtils::getLeadingWhitespace (pos.getLineText())); break; } } diff --git a/modules/juce_core/containers/juce_SortedSet.h b/modules/juce_core/containers/juce_SortedSet.h index f41233b8b2..f18b533782 100644 --- a/modules/juce_core/containers/juce_SortedSet.h +++ b/modules/juce_core/containers/juce_SortedSet.h @@ -269,10 +269,11 @@ public: the objects which were not recognised by the object's operator==, then the set will always contain a copy of the most recently added one. - @param newElement the new object to add to the set + @param newElement the new object to add to the set + @returns true if the value was added, or false if it already existed @see set, insert, addIfNotAlreadyThere, addSorted, addSet, addArray */ - void add (const ElementType& newElement) noexcept + bool add (const ElementType& newElement) noexcept { const ScopedLockType lock (getLock()); @@ -285,7 +286,7 @@ public: if (newElement == elem) { elem = newElement; // force an update in case operator== permits differences. - return; + return false; } const int halfway = (s + e) / 2; @@ -305,6 +306,7 @@ public: } data.insert (s, newElement); + return true; } /** Adds elements from an array to this set.