Skip to content

Commit f8e3fa5

Browse files
committed
Docs
1 parent d0f16b8 commit f8e3fa5

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

Sources/CodeEditTextView/TextLine/Typesetter/CTLineTypesetData.swift

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import AppKit
99

10+
/// Represents layout information received from a `CTTypesetter` for a `CTLine`.
1011
struct CTLineTypesetData {
1112
let ctLine: CTLine
1213
let descent: CGFloat

Sources/CodeEditTextView/TextLine/Typesetter/LineFragmentTypesetContext.swift

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import CoreGraphics
99

10+
/// Represents partial parsing state for typesetting a line fragment.Used once during typesetting and then discarded.
1011
struct LineFragmentTypesetContext {
1112
var contents: [LineFragment.FragmentContent] = []
1213
var start: Int

Sources/CodeEditTextView/TextLine/Typesetter/TypesetContext.swift

+17-2
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@
77

88
import Foundation
99

10+
/// Represents partial parsing state for typesetting a line.Used once during typesetting and then discarded.
11+
/// Contains a few methods for appending data or popping the current line data.
1012
struct TypesetContext {
1113
let documentRange: NSRange
1214
let displayData: TextLine.DisplayData
1315

1416
/// Accumulated generated line fragments.
1517
var lines: [TextLineStorage<LineFragment>.BuildItem] = []
1618
var maxHeight: CGFloat = 0
17-
var fragmentContext: LineFragmentTypesetContext = .init(start: 0, width: 0.0, height: 0.0, descent: 0.0)
19+
/// The current fragment typesetting context.
20+
var fragmentContext = LineFragmentTypesetContext(start: 0, width: 0.0, height: 0.0, descent: 0.0)
1821

1922
/// Tracks the current position when laying out runs
2023
var currentPosition: Int = 0
2124

25+
// MARK: - Fragment Context Modification
26+
27+
/// Appends an attachment to the current ``fragmentContext``
28+
/// - Parameter attachment: The type-erased attachment to append.
2229
mutating func appendAttachment(_ attachment: AnyTextAttachment) {
2330
// Check if we can append this attachment to the current line
2431
if fragmentContext.width + attachment.width > displayData.maxWidth {
@@ -33,7 +40,12 @@ struct TypesetContext {
3340
fragmentContext.height = fragmentContext.height == 0 ? maxHeight : fragmentContext.height
3441
currentPosition += attachment.range.length
3542
}
36-
43+
44+
/// Appends a text range to the current ``fragmentContext``
45+
/// - Parameters:
46+
/// - typesettingRange: The range relative to the typesetter for the current fragment context.
47+
/// - lineBreak: The position that the text fragment should end at, relative to the typesetter's range.
48+
/// - typesetData: Data received from the typesetter.
3749
mutating func appendText(typesettingRange: NSRange, lineBreak: Int, typesetData: CTLineTypesetData) {
3850
fragmentContext.contents.append(
3951
.init(data: .text(line: typesetData.ctLine), width: typesetData.width)
@@ -44,6 +56,9 @@ struct TypesetContext {
4456
currentPosition = lineBreak + typesettingRange.location
4557
}
4658

59+
// MARK: - Pop Fragments
60+
61+
/// Pop the current fragment state into a new line fragment, and reset the fragment state.
4762
mutating func popCurrentData() {
4863
let fragment = LineFragment(
4964
documentRange: NSRange(

0 commit comments

Comments
 (0)