Skip to content

Commit

Permalink
fix: [AttributedLabel] Correct typo in enumeration (square#461)
Browse files Browse the repository at this point in the history
* fix: [AttributedLabel] Correct typo in enumeration

* Document and clarify usage
  • Loading branch information
nononoah authored Jul 17, 2023
1 parent f9bad5f commit 6753a86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
23 changes: 12 additions & 11 deletions BlueprintUICommonControls/Sources/AttributedLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -347,25 +347,26 @@ extension AttributedLabel {

private func links(at location: CGPoint) -> [Link] {
guard let textStorage = makeTextStorage(),
textStorage.string.isEmpty == false,
let layoutManager = textStorage.layoutManagers.first,
let textContainer = layoutManager.textContainers.first
else {
return []
}

func alignmentMultiplier() -> CGFloat {
var alignment: NSTextAlignment = .natural

textStorage.enumerateAttribute(
.paragraphStyle,
in: textStorage.entireRange,
options: []
) { style, range, continuePointer in
if let style = style as? NSParagraphStyle, range == textStorage.entireRange {
alignment = style.alignment
continuePointer.pointee = false
// If a paragraph style spans the range of the text, use its alignment.
// Otherwise, fall back to `.natural`.
let alignment: NSTextAlignment = {
var range: NSRange = NSRange(location: -1, length: 0)
let style = textStorage.attribute(.paragraphStyle, at: 0, effectiveRange: &range)

guard let style = style as? NSParagraphStyle, range == textStorage.entireRange else {
return .natural
}
}

return style.alignment
}()

switch (alignment, layoutDirection) {
case (.left, _),
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Internal

- Update CI script to reference the `xcodesorg/made/xcodes` package for installing simulator runtimes.
- Corrected a typo in `AttributedLabel`, which now exits paragraph style enumeration after encountering the first paragraph style. This is an optimization and not a functional change. The method continues to accept only a paragraph style which spans the length of the attributed string.

# Past Releases

Expand Down

0 comments on commit 6753a86

Please sign in to comment.