@@ -87,30 +87,28 @@ extension TextLayoutManager {
8787#if DEBUG
8888 var laidOutLines : Set < TextLine . ID > = [ ]
8989#endif
90-
9190 // Layout all lines, fetching lines lazily as they are laid out.
9291 for linePosition in linesStartingAt ( minY, until: maxY) . lazy {
9392 guard linePosition. yPos < maxY else { continue }
9493 // Three ways to determine if a line needs to be re-calculated.
95- let changedWidth = linePosition. data. needsLayout ( maxWidth: maxLineLayoutWidth)
94+ let linePositionNeedsLayout = linePosition. data. needsLayout ( maxWidth: maxLineLayoutWidth)
9695 let wasNotVisible = !visibleLineIds. contains ( linePosition. data. id)
9796 let lineNotEntirelyLaidOut = linePosition. height != linePosition. data. lineFragments. height
9897
99- if forceLayout || changedWidth || wasNotVisible || lineNotEntirelyLaidOut {
98+ if forceLayout || linePositionNeedsLayout || wasNotVisible || lineNotEntirelyLaidOut {
10099 let lineSize = layoutLine (
101100 linePosition,
102101 textStorage: textStorage,
103102 layoutData: LineLayoutData ( minY: minY, maxY: maxY, maxWidth: maxLineLayoutWidth) ,
104103 laidOutFragmentIDs: & usedFragmentIDs
105104 )
106- if lineSize. height != linePosition. height {
105+ let wasLineHeightChanged = lineSize. height != linePosition. height
106+ if wasLineHeightChanged {
107107 lineStorage. update (
108108 atOffset: linePosition. range. location,
109109 delta: 0 ,
110110 deltaHeight: lineSize. height - linePosition. height
111111 )
112- // If we've updated a line's height, force re-layout for the rest of the pass.
113- forceLayout = true
114112
115113 if linePosition. yPos < minY {
116114 // Adjust the scroll position by the difference between the new height and old.
@@ -123,6 +121,14 @@ extension TextLayoutManager {
123121#if DEBUG
124122 laidOutLines. insert ( linePosition. data. id)
125123#endif
124+ // If we've updated a line's height, or a line position was newly laid out, force re-layout for the
125+ // rest of the pass (going down the screen).
126+ //
127+ // These two signals identify:
128+ // - New lines being inserted & Lines being deleted (lineNotEntirelyLaidOut)
129+ // - Line updated for width change (wasLineHeightChanged)
130+
131+ forceLayout = forceLayout || wasLineHeightChanged || lineNotEntirelyLaidOut
126132 } else {
127133 // Make sure the used fragment views aren't dequeued.
128134 usedFragmentIDs. formUnion ( linePosition. data. lineFragments. map ( \. data. id) )
0 commit comments