@@ -1556,10 +1556,10 @@ interface InlineIteratorState {
15561556 layout : Layout ;
15571557 index : number ;
15581558 minlevel : number ;
1559- inlineEnd : number ;
1559+ breakspotIndex : number ;
15601560 buffered : InlineIteratorBuffered [ ] ;
1561- emitBreakspot : boolean ;
15621561 parents : Inline [ ] ;
1562+ isInlineBlock : boolean ;
15631563}
15641564
15651565export function createInlineIteratorState (
@@ -1576,66 +1576,70 @@ export function createInlineIteratorState(
15761576 buffered : [ ] ,
15771577 minlevel : 0 ,
15781578 parents : [ ] ,
1579- inlineEnd : 0 ,
1580- emitBreakspot : false ,
1579+ breakspotIndex : 0 ,
1580+ isInlineBlock : false
15811581 } ;
15821582}
15831583
15841584export function inlineIteratorStateNext ( state : InlineIteratorState ) {
15851585 if ( ! state . buffered . length ) {
1586- while ( state . index <= state . block . treeFinal || state . parents . length ) {
1586+ let foundAtomic = false ;
1587+
1588+ state . breakspotIndex = 0 ;
1589+ state . isInlineBlock = false ;
1590+
1591+ while ( state . index <= state . block . treeFinal && ! foundAtomic ) {
1592+ const item = state . layout . tree [ state . index ] ;
1593+
1594+ if ( item . isInline ( ) ) {
1595+ state . parents . push ( item ) ;
1596+ state . buffered . push ( { state : 'pre' , item} ) ;
1597+ } else {
1598+ foundAtomic = true ;
1599+ state . minlevel = state . parents . length ;
1600+
1601+ if ( item . isRun ( ) ) {
1602+ state . buffered . push ( { state : 'text' , item} ) ;
1603+ } else if ( item . isBreak ( ) ) {
1604+ state . buffered . push ( { state : 'break' } ) ;
1605+ } else {
1606+ if ( item . isFloat ( ) ) {
1607+ state . buffered . push ( { state : 'box' , item} ) ;
1608+ } else {
1609+ state . buffered . push ( { state : 'box' , item} ) ;
1610+ state . isInlineBlock = true ;
1611+ }
1612+ state . index = item . treeFinal ;
1613+ }
1614+ }
1615+
15871616 while (
15881617 state . parents . length &&
1589- state . index - 1 === state . parents . at ( - 1 ) ! . treeFinal
1618+ state . index === state . parents . at ( - 1 ) ! . treeFinal
15901619 ) {
15911620 const parent = state . parents . pop ( ) ! ;
15921621 state . buffered . push ( { state : 'post' , item : parent } ) ;
15931622 if ( state . parents . length <= state . minlevel ) {
1594- state . inlineEnd = state . buffered . length ;
1623+ if ( ! foundAtomic ) state . breakspotIndex = state . buffered . length ;
15951624 state . minlevel = state . parents . length ;
15961625 }
15971626 }
15981627
1599- if ( state . index <= state . block . treeFinal ) {
1600- const item = state . layout . tree [ state . index ++ ] ;
1628+ state . index ++ ;
1629+ }
16011630
1602- if ( item . isInline ( ) ) {
1603- state . parents . push ( item ) ;
1604- state . buffered . push ( { state : 'pre' , item} ) ;
1605- } else {
1606- state . emitBreakspot = state . minlevel !== state . parents . length ;
1607- state . minlevel = state . parents . length ;
1608- if ( item . isRun ( ) ) {
1609- state . buffered . push ( { state : 'text' , item} ) ;
1610- } else if ( item . isBreak ( ) ) {
1611- state . buffered . push ( { state : 'break' } ) ;
1612- } else {
1613- if ( item . isFloat ( ) ) {
1614- state . emitBreakspot = true ;
1615- state . buffered . push ( { state : 'box' , item} ) ;
1616- } else {
1617- state . buffered . push (
1618- { state : 'breakop' } ,
1619- { state : 'box' , item} ,
1620- { state : 'breakop' }
1621- ) ;
1622- }
1623- state . index = item . treeFinal + 1 ;
1624- }
1625- break ;
1626- }
1627- }
1631+ if ( foundAtomic && state . isInlineBlock ) {
1632+ state . buffered . push ( { state : 'breakop' } ) ;
16281633 }
16291634 }
16301635
16311636 if ( state . buffered . length ) {
1632- if ( state . inlineEnd === 0 && state . emitBreakspot ) {
1633- state . emitBreakspot = false ;
1634- state . value = { state : 'breakspot' } ;
1637+ if ( state . breakspotIndex === 0 ) {
1638+ state . value = { state : state . isInlineBlock ? 'breakop' : 'breakspot' } ;
16351639 } else {
1636- if ( state . inlineEnd > 0 ) state . inlineEnd -= 1 ;
16371640 state . value = state . buffered . shift ( ) ! ;
16381641 }
1642+ state . breakspotIndex -= 1 ;
16391643 } else {
16401644 state . value = null ;
16411645 }
0 commit comments