Skip to content

Commit 8d5d376

Browse files
committed
Refactor gutter view calculations to use scroll view consistently and mark certain properties as @mainactor for thread safety. Adjust font and text color handling to ensure layout updates properly.
1 parent 056ce1a commit 8d5d376

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Sources/STTextViewAppKit/STTextView+Gutter.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ extension STTextView {
108108

109109
gutterView.containerView.addSubview(numberCell)
110110
}
111-
} else if let viewportRange = textLayoutManager.textViewportLayoutController.viewportRange {
111+
} else if let scrollView, let viewportRange = textLayoutManager.textViewportLayoutController.viewportRange {
112112

113113
let textElements = textContentManager.textElements(
114114
for: NSTextRange(
@@ -154,7 +154,7 @@ extension STTextView {
154154
let lineNumber = startLineIndex + linesCount + 1
155155
let locationForFirstCharacter = lineFragment.locationForCharacter(at: 0)
156156

157-
var lineFragmentFrame = CGRect(origin: CGPoint(x: 0, y: layoutFragment.layoutFragmentFrame.origin.y - scrollView!.contentView.bounds.minY/*contentOffset.y*/), size: layoutFragment.layoutFragmentFrame.size)
157+
var lineFragmentFrame = CGRect(origin: CGPoint(x: 0, y: layoutFragment.layoutFragmentFrame.origin.y - scrollView.contentView.bounds.minY/*contentOffset.y*/), size: layoutFragment.layoutFragmentFrame.size)
158158

159159
lineFragmentFrame.origin.y += lineFragment.typographicBounds.origin.y
160160
if lineFragment.isExtraLineFragment {

Sources/STTextViewAppKit/STTextView.swift

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import AVFoundation
8989
///
9090
/// Assigning a new value to this property causes the new font to be applied to the entire contents of the text view.
9191
/// If you want to apply the font to only a portion of the text, you must create a new attributed string with the desired style information and assign it
92+
@MainActor
9293
@objc public var font: NSFont {
9394
get {
9495
_defaultTypingAttributes[.font] as! NSFont
@@ -100,6 +101,8 @@ import AVFoundation
100101
// apply to the document
101102
if !textLayoutManager.documentRange.isEmpty {
102103
addAttributes([.font: newValue], range: textLayoutManager.documentRange)
104+
needsLayout = true
105+
needsDisplay = true
103106
}
104107

105108
updateTypingAttributes()
@@ -109,6 +112,7 @@ import AVFoundation
109112
/// The text color of the text view.
110113
///
111114
/// Default text color.
115+
@MainActor
112116
@objc public var textColor: NSColor {
113117
get {
114118
_defaultTypingAttributes[.foregroundColor] as! NSColor
@@ -120,6 +124,7 @@ import AVFoundation
120124
}
121125

122126
/// Default paragraph style.
127+
@MainActor
123128
@objc public var defaultParagraphStyle: NSParagraphStyle {
124129
set {
125130
_defaultTypingAttributes[.paragraphStyle] = newValue
@@ -1381,6 +1386,7 @@ import AVFoundation
13811386
}
13821387
}
13831388

1389+
@MainActor
13841390
private func setUp(instance: some STPlugin) -> STPluginEvents {
13851391
// unwrap any STPluginProtocol
13861392
let events = STPluginEvents()

0 commit comments

Comments
 (0)