Avoid space-wrapping while inside xy special case

This commit is contained in:
Jon Evans 2023-11-18 18:54:27 -05:00
parent 0face5a891
commit b13e244dc5
1 changed files with 7 additions and 2 deletions

View File

@ -88,6 +88,7 @@ void Prettify( std::string& aSource, char aQuoteChar )
bool inQuote = false; bool inQuote = false;
bool hasInsertedSpace = false; bool hasInsertedSpace = false;
bool inMultiLineList = false; bool inMultiLineList = false;
bool inXY = false;
int column = 0; int column = 0;
auto isWhitespace = []( const char aChar ) auto isWhitespace = []( const char aChar )
@ -135,7 +136,7 @@ void Prettify( std::string& aSource, char aQuoteChar )
&& next != ')' // Remove extra space before end of list && next != ')' // Remove extra space before end of list
&& next != '(' ) // Remove extra space before newline && next != '(' ) // Remove extra space before newline
{ {
if( column < consecutiveTokenWrapThreshold ) if( inXY || column < consecutiveTokenWrapThreshold )
{ {
// Note that we only insert spaces here, no matter what kind of whitespace is in // Note that we only insert spaces here, no matter what kind of whitespace is in
// the input. Newlines will be inserted as needed by the logic below. // the input. Newlines will be inserted as needed by the logic below.
@ -159,16 +160,19 @@ void Prettify( std::string& aSource, char aQuoteChar )
if( *cursor == '(' && !inQuote ) if( *cursor == '(' && !inQuote )
{ {
bool currentIsXY = isXY( cursor );
if( listDepth == 0 ) if( listDepth == 0 )
{ {
formatted.push_back( '(' ); formatted.push_back( '(' );
column++; column++;
} }
else if( isXY( cursor ) && column < xySpecialCaseColumnLimit ) else if( inXY && currentIsXY && column < xySpecialCaseColumnLimit )
{ {
// List-of-points special case // List-of-points special case
formatted += " ("; formatted += " (";
column += 2; column += 2;
inXY = true;
} }
else else
{ {
@ -177,6 +181,7 @@ void Prettify( std::string& aSource, char aQuoteChar )
column = listDepth * indentSize + 1; column = listDepth * indentSize + 1;
} }
inXY = currentIsXY;
listDepth++; listDepth++;
} }
else if( *cursor == ')' && !inQuote ) else if( *cursor == ')' && !inQuote )