Skip to content

Commit 2ef1f12

Browse files
committed
Rearrange Break Strategy into DisplayData
1 parent 4427899 commit 2ef1f12

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

Sources/CodeEditTextView/TextLayoutManager/TextLayoutManager+Layout.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ extension TextLayoutManager {
167167
let lineDisplayData = TextLine.DisplayData(
168168
maxWidth: layoutData.maxWidth,
169169
lineHeightMultiplier: lineHeightMultiplier,
170-
estimatedLineHeight: estimateLineHeight()
170+
estimatedLineHeight: estimateLineHeight(),
171+
breakStrategy: lineBreakStrategy
171172
)
172173

173174
let line = position.data
@@ -187,7 +188,6 @@ extension TextLayoutManager {
187188
range: position.range,
188189
stringRef: textStorage,
189190
markedRanges: markedTextManager.markedRanges(in: position.range),
190-
breakStrategy: lineBreakStrategy,
191191
attachments: attachments.get(startingIn: position.range)
192192
)
193193
}

Sources/CodeEditTextView/TextLayoutManager/TextLayoutManagerRenderDelegate.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public extension TextLayoutManagerRenderDelegate {
4444
range: range,
4545
stringRef: stringRef,
4646
markedRanges: markedRanges,
47-
breakStrategy: breakStrategy,
4847
attachments: attachments
4948
)
5049
}

Sources/CodeEditTextView/TextLine/TextLine.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ public final class TextLine: Identifiable, Equatable {
4848
/// - range: The range this text range represents in the entire document.
4949
/// - stringRef: A reference to the string storage for the document.
5050
/// - markedRanges: Any marked ranges in the line.
51-
/// - breakStrategy: Determines how line breaks are calculated.
51+
/// - attachments: Any attachments overlapping the line range.
5252
public func prepareForDisplay(
5353
displayData: DisplayData,
5454
range: NSRange,
5555
stringRef: NSTextStorage,
5656
markedRanges: MarkedRanges?,
57-
breakStrategy: LineBreakStrategy,
5857
attachments: [TextAttachmentBox]
5958
) {
6059
let string = stringRef.attributedSubstring(from: range)
@@ -63,7 +62,6 @@ public final class TextLine: Identifiable, Equatable {
6362
string,
6463
documentRange: range,
6564
displayData: displayData,
66-
breakStrategy: breakStrategy,
6765
markedRanges: markedRanges,
6866
attachments: attachments
6967
)
@@ -79,11 +77,18 @@ public final class TextLine: Identifiable, Equatable {
7977
public let maxWidth: CGFloat
8078
public let lineHeightMultiplier: CGFloat
8179
public let estimatedLineHeight: CGFloat
80+
public let breakStrategy: LineBreakStrategy
8281

83-
public init(maxWidth: CGFloat, lineHeightMultiplier: CGFloat, estimatedLineHeight: CGFloat) {
82+
public init(
83+
maxWidth: CGFloat,
84+
lineHeightMultiplier: CGFloat,
85+
estimatedLineHeight: CGFloat,
86+
breakStrategy: LineBreakStrategy = .character
87+
) {
8488
self.maxWidth = maxWidth
8589
self.lineHeightMultiplier = lineHeightMultiplier
8690
self.estimatedLineHeight = estimatedLineHeight
91+
self.breakStrategy = breakStrategy
8792
}
8893
}
8994
}

Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ final public class Typesetter {
3131
_ string: NSAttributedString,
3232
documentRange: NSRange,
3333
displayData: TextLine.DisplayData,
34-
breakStrategy: LineBreakStrategy,
3534
markedRanges: MarkedRanges?,
3635
attachments: [TextAttachmentBox] = []
3736
) {
@@ -46,7 +45,6 @@ final public class Typesetter {
4645
let (lines, maxHeight) = typesetLineFragments(
4746
documentRange: documentRange,
4847
displayData: displayData,
49-
breakStrategy: breakStrategy,
5048
attachments: attachments
5149
)
5250
lineFragments.build(from: lines, estimatedLineHeight: maxHeight)
@@ -121,7 +119,6 @@ final public class Typesetter {
121119
func typesetLineFragments(
122120
documentRange: NSRange,
123121
displayData: TextLine.DisplayData,
124-
breakStrategy: LineBreakStrategy,
125122
attachments: [TextAttachmentBox]
126123
) -> (lines: [TextLineStorage<LineFragment>.BuildItem], maxHeight: CGFloat) {
127124
let contentRuns = createContentRuns(documentRange: documentRange, attachments: attachments)
@@ -136,8 +133,7 @@ final public class Typesetter {
136133
context: &context,
137134
range: run.range,
138135
typesetter: typesetter,
139-
displayData: displayData,
140-
breakStrategy: breakStrategy
136+
displayData: displayData
141137
)
142138
}
143139
}
@@ -155,16 +151,15 @@ final public class Typesetter {
155151
context: inout TypesetContext,
156152
range: NSRange,
157153
typesetter: CTTypesetter,
158-
displayData: TextLine.DisplayData,
159-
breakStrategy: LineBreakStrategy
154+
displayData: TextLine.DisplayData
160155
) {
161156
// Layout as many fragments as possible in this content run
162157
while context.currentPosition < range.max {
163158
// The line break indicates the distance from the range we’re typesetting on that should be broken at.
164159
// It's relative to the range being typeset, not the line
165160
let lineBreak = typesetter.suggestLineBreak(
166161
using: string,
167-
strategy: breakStrategy,
162+
strategy: displayData.breakStrategy,
168163
startingOffset: context.currentPosition - range.location,
169164
constrainingWidth: displayData.maxWidth - context.fragmentContext.width
170165
)

0 commit comments

Comments
 (0)