Skip to content

Commit 7032997

Browse files
Use flatMap
1 parent d1f56d6 commit 7032997

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

Sources/CodeEditTextView/EmphasisManager/EmphasisManager.swift

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,28 +168,26 @@ public final class EmphasisManager {
168168

169169
/// Updates the positions and bounds of all emphasis layers to match the current text layout.
170170
public func updateLayerBackgrounds() {
171-
for (_, layers) in emphasisGroups {
172-
for layer in layers {
173-
if let shapePath = textView?.layoutManager?.roundedPathForRange(layer.emphasis.range) {
174-
if #available(macOS 14.0, *) {
175-
layer.layer.path = shapePath.cgPath
176-
} else {
177-
layer.layer.path = shapePath.cgPathFallback
178-
}
171+
for layer in emphasisGroups.flatMap(\.value) {
172+
if let shapePath = textView?.layoutManager?.roundedPathForRange(layer.emphasis.range) {
173+
if #available(macOS 14.0, *) {
174+
layer.layer.path = shapePath.cgPath
175+
} else {
176+
layer.layer.path = shapePath.cgPathFallback
177+
}
179178

180-
// Update bounds and position
181-
if let cgPath = layer.layer.path {
182-
let boundingBox = cgPath.boundingBox
183-
layer.layer.bounds = boundingBox
184-
layer.layer.position = CGPoint(x: boundingBox.midX, y: boundingBox.midY)
185-
}
179+
// Update bounds and position
180+
if let cgPath = layer.layer.path {
181+
let boundingBox = cgPath.boundingBox
182+
layer.layer.bounds = boundingBox
183+
layer.layer.position = CGPoint(x: boundingBox.midX, y: boundingBox.midY)
184+
}
186185

187-
// Update text layer if it exists
188-
if let textLayer = layer.textLayer {
189-
var bounds = shapePath.bounds
190-
bounds.origin.y += 1 // Move down by 1 pixel
191-
textLayer.frame = bounds
192-
}
186+
// Update text layer if it exists
187+
if let textLayer = layer.textLayer {
188+
var bounds = shapePath.bounds
189+
bounds.origin.y += 1 // Move down by 1 pixel
190+
textLayer.frame = bounds
193191
}
194192
}
195193
}

0 commit comments

Comments
 (0)