registerInStatementIndent: Align with the next non-whitespace character

This commit is contained in:
Peter Vingelmann 2016-09-16 20:58:01 +02:00
parent c9a243fd41
commit 5c9aefd388

View File

@ -1261,10 +1261,12 @@ void ASBeautifier::registerInStatementIndent(const string& line, int i, int spac
int tabIncrementIn, int minIndent, bool updateParenStack) int tabIncrementIn, int minIndent, bool updateParenStack)
{ {
int remainingCharNum = line.length() - i; int remainingCharNum = line.length() - i;
int nextNonWSChar = getNextProgramCharDistance(line, i); // Get the next program char distance to determine if the remaining
// text is comment-only
int nextProgramChar = getNextProgramCharDistance(line, i);
// if indent is around the last char in the line, indent instead one indent from the previous indent // if indent is around the last char in the line, indent instead one indent from the previous indent
if (nextNonWSChar == remainingCharNum) if (nextProgramChar == remainingCharNum)
{ {
int previousIndent = spaceTabCount_; int previousIndent = spaceTabCount_;
if (!inStatementIndentStack->empty()) if (!inStatementIndentStack->empty())
@ -1279,6 +1281,13 @@ void ASBeautifier::registerInStatementIndent(const string& line, int i, int spac
return; return;
} }
// The next line should be aligned with the next non-whitespace character.
// This character could be a beginning of a comment
int nextNonWSChar = 1;
size_t nextCharPos = line.find_first_not_of(" \t", i + 1);
if (nextCharPos != string::npos)
nextNonWSChar = nextCharPos - i;
if (updateParenStack) if (updateParenStack)
parenIndentStack->push_back(i + spaceTabCount_ - horstmannIndentInStatement); parenIndentStack->push_back(i + spaceTabCount_ - horstmannIndentInStatement);