@@ -1537,13 +1537,29 @@ fn flip_unsplit_lines_impl(lines: Vec<Vec<Sp<Word>>>, in_array: bool) -> Vec<Vec
1537
1537
. last ( )
1538
1538
. is_some_and ( |w| matches ! ( w. value, Word :: FlipLine ) ) ;
1539
1539
1540
+ let trim_spaces = |words : & mut Vec < Sp < Word > > | {
1541
+ while ( words. first ( ) ) . is_some_and ( |w| matches ! ( w. value, Word :: Spaces ) ) {
1542
+ words. remove ( 0 ) ;
1543
+ }
1544
+ while words
1545
+ . last ( )
1546
+ . is_some_and ( |w| matches ! ( w. value, Word :: Spaces ) )
1547
+ {
1548
+ words. pop ( ) ;
1549
+ }
1550
+ } ;
1551
+
1540
1552
let flip_line = |mut line : Vec < Sp < Word > > | {
1541
1553
if line. iter ( ) . any ( |w| matches ! ( w. value, Word :: FlipLine ) ) {
1542
1554
let mut parts = Vec :: new ( ) ;
1543
1555
while let Some ( i) = ( line. iter ( ) ) . rposition ( |w| matches ! ( w. value, Word :: FlipLine ) ) {
1544
- parts. push ( line. split_off ( i + 1 ) ) ;
1545
- line. pop ( ) ;
1556
+ let mut part = line. split_off ( i + 1 ) ;
1557
+ trim_spaces ( & mut part) ;
1558
+ parts. push ( part) ;
1559
+ let span = line. pop ( ) . unwrap ( ) . span ;
1560
+ parts. push ( vec ! [ span. sp( Word :: Spaces ) ] ) ;
1546
1561
}
1562
+ trim_spaces ( & mut line) ;
1547
1563
parts. push ( line) ;
1548
1564
line = parts. into_iter ( ) . flatten ( ) . collect ( ) ;
1549
1565
}
@@ -1553,13 +1569,7 @@ fn flip_unsplit_lines_impl(lines: Vec<Vec<Sp<Word>>>, in_array: bool) -> Vec<Vec
1553
1569
let mut new_lines = vec ! [ flip_line( first) ] ;
1554
1570
1555
1571
for mut line in lines {
1556
- // Trim spaces
1557
- while ( line. first ( ) ) . is_some_and ( |w| matches ! ( w. value, Word :: Spaces ) ) {
1558
- line. remove ( 0 ) ;
1559
- }
1560
- while line. last ( ) . is_some_and ( |w| matches ! ( w. value, Word :: Spaces ) ) {
1561
- line. pop ( ) ;
1562
- }
1572
+ trim_spaces ( & mut line) ;
1563
1573
// Check for leading and trailing unbreak lines
1564
1574
let unsplit_front = ( line. first ( ) ) . is_some_and ( |w| matches ! ( w. value, Word :: FlipLine ) ) ;
1565
1575
if unsplit_front {
0 commit comments