File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Sources/CodeEditTextView/TextLayoutManager
Tests/CodeEditTextViewTests Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,14 @@ public class TextLayoutManager: NSObject {
5555 }
5656 }
5757
58- public weak var renderDelegate : TextLayoutManagerRenderDelegate ?
58+ public weak var renderDelegate : TextLayoutManagerRenderDelegate ? {
59+ didSet {
60+ // Rebuild using potentially overridden behavior.
61+ _estimateLineHeight = nil
62+ lineStorage. removeAll ( )
63+ prepareTextLines ( )
64+ }
65+ }
5966
6067 // MARK: - Internal
6168
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ class MockRenderDelegate: TextLayoutManagerRenderDelegate {
1212 _ breakStrategy: LineBreakStrategy
1313 ) -> Void ) ?
1414
15+ var estimatedLineHeightOverride : ( ( ) -> CGFloat ) ?
16+
1517 func prepareForDisplay( // swiftlint:disable:this function_parameter_count
1618 textLine: TextLine ,
1719 displayData: TextLine . DisplayData ,
@@ -35,6 +37,10 @@ class MockRenderDelegate: TextLayoutManagerRenderDelegate {
3537 breakStrategy: breakStrategy
3638 )
3739 }
40+
41+ func estimatedLineHeight( ) -> CGFloat ? {
42+ estimatedLineHeightOverride ? ( )
43+ }
3844}
3945
4046@Suite
@@ -92,4 +98,17 @@ struct OverridingLayoutManagerRenderingTests {
9298 #expect( layoutManager. lineStorage. height == 14.0 )
9399 layoutManager. lineStorage. validateInternalState ( )
94100 }
101+
102+ @Test
103+ func overriddenEstimatedLineHeight( ) {
104+ // The layout manager should use the estimation from the render delegate, not the font size.
105+ mockDelegate. estimatedLineHeightOverride = {
106+ 1.0
107+ }
108+
109+ layoutManager. renderDelegate = mockDelegate
110+
111+ #expect( layoutManager. estimateLineHeight ( ) == 1.0 )
112+ #expect( layoutManager. estimatedHeight ( ) == 4.0 ) // 4 lines, each 1 high
113+ }
95114}
You can’t perform that action at this time.
0 commit comments