File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed 
Sources/SwiftFormat/PrettyPrint Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -122,17 +122,16 @@ struct PrettyPrintBuffer {
122122    // In case of comments, we may get a multi-line string.
123123    // To account for that case, we need to correct the lineNumber count.
124124    // The new column is only the position within the last line.
125-     var   lastLength  =  0 
126-     // We are only interested in "\n" we can use the UTF8 view and skip the grapheme clustering. 
127-     for   element   in  text . utf8  { 
128-       if  element  ==   UInt8 ( ascii :   " \n " )   { 
129-         lineNumber  +=   1 
130-         lastLength  =   0 
131-       }   else   { 
132-         lastLength  +=   1 
133-       } 
125+     let   lines  =  text . split ( separator :   " \n " ) 
126+     lineNumber  +=  lines . count  -   1 
127+     if  lines . count  >   1  { 
128+       // in case we have inserted new lines, we need to reset the column 
129+       column  =  lines . last ? . count  ??   0 
130+     }   else   { 
131+       // in case it is an end of line comment or a single line comment, 
132+       // we just add to the current column 
133+       column  +=  lines . last ? . count  ??   0 
134134    } 
135-     column +=  lastLength
136135  } 
137136
138137  /// Request that the given number of spaces be printed out before the next text token.
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments