@@ -783,6 +783,19 @@ private function advanceCurrentPosition(int $newPosition)
783783 return ;
784784 }
785785
786+ /*
787+ * A bit of a workaround. At times, this function will be called when the
788+ * position is at the beginning of the line: so, one character *after*
789+ * a line break. In that case, if there are a group of spaces at the
790+ * beginning of this first line, they *should* be used to calculate the new
791+ * indentation. To force this, if we detect this situation, we move one
792+ * character backwards, so that the first line is considered a valid line
793+ * to look for indentation.
794+ */
795+ if ($ this ->isCharLineBreak (substr ($ this ->contents , $ originalPosition - 1 , 1 ))) {
796+ $ originalPosition --;
797+ }
798+
786799 // look for empty lines and track the current indentation
787800 $ advancedContent = substr ($ this ->contents , $ originalPosition , $ newPosition - $ originalPosition );
788801 $ previousIndentation = $ this ->indentationForDepths [$ this ->depth ];
@@ -872,7 +885,11 @@ private function guessNextArrayTypeAndAdvance(): string
872885
873886 // get the next char & advance immediately
874887 $ nextCharacter = substr ($ this ->contents , $ this ->currentPosition , 1 );
875- $ this ->advanceCurrentPosition ($ this ->currentPosition + 1 );
888+ // advance, but without advanceCurrentPosition()
889+ // because we are either moving along one line until [ {
890+ // or we are finding a line break and stopping: indentation
891+ // should not be calculated
892+ $ this ->currentPosition ++;
876893
877894 if ($ this ->isCharLineBreak ($ nextCharacter )) {
878895 return self ::ARRAY_FORMAT_MULTILINE ;
0 commit comments