diff --git a/Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager+Public.swift b/Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager+Public.swift index df1eb943..938950ac 100644 --- a/Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager+Public.swift +++ b/Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager+Public.swift @@ -13,7 +13,7 @@ extension TextLayoutManager { } public func estimatedWidth() -> CGFloat { - maxLineWidth + maxLineWidth + edgeInsets.horizontal } /// Finds a text line for the given y position relative to the text view. diff --git a/Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager.swift b/Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager.swift index d28be05d..788c76b6 100644 --- a/Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager.swift +++ b/Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager.swift @@ -266,10 +266,6 @@ public class TextLayoutManager: NSObject { // Update the visible lines with the new set. visibleLineIds = newVisibleLines - if originalHeight != lineStorage.height || layoutView?.frame.size.height != lineStorage.height { - delegate?.layoutManagerHeightDidUpdate(newHeight: lineStorage.height) - } - if maxFoundLineWidth > maxLineWidth { maxLineWidth = maxFoundLineWidth } @@ -282,6 +278,11 @@ public class TextLayoutManager: NSObject { isInLayout = false #endif needsLayout = false + + // This needs to happen after ``needsLayout`` is toggled. Things can be triggered by frame changes. + if originalHeight != lineStorage.height || layoutView?.frame.size.height != lineStorage.height { + delegate?.layoutManagerHeightDidUpdate(newHeight: lineStorage.height) + } } /// Lays out a single text line. diff --git a/Sources/CodeEditTextView/TextView/TextView+Layout.swift b/Sources/CodeEditTextView/TextView/TextView+Layout.swift index 11c8ddc5..a68d78be 100644 --- a/Sources/CodeEditTextView/TextView/TextView+Layout.swift +++ b/Sources/CodeEditTextView/TextView/TextView+Layout.swift @@ -83,7 +83,7 @@ extension TextView { if didUpdate { needsLayout = true needsDisplay = true - layoutManager.layoutLines() + layoutManager.setNeedsLayout() } if isSelectable {