@@ -280,34 +280,18 @@ That minimum indentation is stripped off every line that already has that much i
280280and then _all_ lines are re-indented with the discovered minimum.
281281}
282282private str subIndent (loc span , str replacement , str original ) {
283- list [str ] indents (str text ) = [indent | /^<indent :[\t \ ]*> [^\ \t]/ <- split ("\n " , text )];
284-
285- origIndents = indents (original );
286- replLines = split ("\n " , replacement );
287-
288- if (replLines == []) {
283+ if (trim (replacement ) == "" ) {
289284 return "" ;
290285 }
291286
292- minIndent = "" ;
287+ // note that box2text can only produce ASCII spaces or tabs
288+ indents = [indent | /^<indent :[\t \ ]*> [^\ \t]/ <- split ("\n " , original )];
293289
294- if ([_] := origIndents ) {
295- // only one line. have to invent indentation from span
296- minIndent = "<for (_ <- [0 ..(span .begin ?) ? span .begin .column : 0 ]) {> <}> " ;
297- }
298- else {
299- // we skip the first line for learning indentation, because that one would typically be embedded in a previous line.
300- minIndent = sort (origIndents [1 ..])[0 ]? "" ;
301- }
290+ minIndent = [_] := indents
291+ ? "<for (_ <- [0 ..(span .begin ?) ? span .begin .column : 0 ]) {> <}> "
292+ : sort (indents [1 ..])[0 ]? "" ;
302293
303- // we remove the leading spaces _up to_ the minimal indentation of the original,
304- // keep the rest of the indentation from the replacement (if any is left), and then the actual content.
305- // that entire multiline result is then lazily indented with the minimal indentation we learned from the original.
306- return indent (
307- minIndent ,
308- "<for (/^<theInd :[\t \ ]*><rest :[^\t \ ]+.*> $/ <- replLines ) {><theInd [..max (size (minIndent ), span .begin ? ? span .begin .column : 0 )]><rest >
309- '<}> " [..-1 ])
310- ;
294+ return indent (minIndent , replacement );
311295}
312296
313297@synopsis {Generates an HTML-based preview of the result of formatting.}
0 commit comments