Skip to content

Commit 3ddd279

Browse files
Fix Padding Issue, Assertion Failure On Width Update (#53)
1 parent e5369da commit 3ddd279

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager+Public.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension TextLayoutManager {
1313
}
1414

1515
public func estimatedWidth() -> CGFloat {
16-
maxLineWidth
16+
maxLineWidth + edgeInsets.horizontal
1717
}
1818

1919
/// Finds a text line for the given y position relative to the text view.

Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,6 @@ public class TextLayoutManager: NSObject {
266266
// Update the visible lines with the new set.
267267
visibleLineIds = newVisibleLines
268268

269-
if originalHeight != lineStorage.height || layoutView?.frame.size.height != lineStorage.height {
270-
delegate?.layoutManagerHeightDidUpdate(newHeight: lineStorage.height)
271-
}
272-
273269
if maxFoundLineWidth > maxLineWidth {
274270
maxLineWidth = maxFoundLineWidth
275271
}
@@ -282,6 +278,11 @@ public class TextLayoutManager: NSObject {
282278
isInLayout = false
283279
#endif
284280
needsLayout = false
281+
282+
// This needs to happen after ``needsLayout`` is toggled. Things can be triggered by frame changes.
283+
if originalHeight != lineStorage.height || layoutView?.frame.size.height != lineStorage.height {
284+
delegate?.layoutManagerHeightDidUpdate(newHeight: lineStorage.height)
285+
}
285286
}
286287

287288
/// Lays out a single text line.

Sources/CodeEditTextView/TextView/TextView+Layout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ extension TextView {
8383
if didUpdate {
8484
needsLayout = true
8585
needsDisplay = true
86-
layoutManager.layoutLines()
86+
layoutManager.setNeedsLayout()
8787
}
8888

8989
if isSelectable {

0 commit comments

Comments
 (0)