Skip to content

Add OpenSwiftUI attributed string and text scale support - #892

Merged
Kyle-Ye merged 10 commits into
mainfrom
feature/attribute_scope
Jun 7, 2026
Merged

Add OpenSwiftUI attributed string and text scale support#892
Kyle-Ye merged 10 commits into
mainfrom
feature/attribute_scope

Conversation

@Kyle-Ye

@Kyle-Ye Kyle-Ye commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Add AttributeScopes.OpenSwiftUIAttributes and OpenSwiftUI attributed string attribute definitions.
  • Implement attributed-string-backed Text storage, style transfer, platform attributed string conversion, and localized formatting support.
  • Add Text.Scale APIs and tests.
  • Add non-Darwin inline presentation intent shims needed for Linux attributed string support.

@github-actions github-actions Bot added area: text Text, labels, line style, and text rendering APIs. platform: Linux Linux-specific behavior or support. type: feature New API, behavior, platform support, or user-facing capability. labels Jun 7, 2026
@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 4.60705% with 352 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.68%. Comparing base (1d01474) to head (2ee5de6).

Files with missing lines Patch % Lines
.../Text/AttributedString/Text+AttributedString.swift 0.00% 208 Missing ⚠️
...penSwiftUICore/View/Text/Text/Text+Localized.swift 0.00% 66 Missing ⚠️
...nSwiftUICore/View/Text/Util/String+Extension.swift 0.00% 51 Missing ⚠️
...es/OpenSwiftUICore/View/Text/Text/Text+Scale.swift 53.84% 12 Missing ⚠️
...wiftUICore/View/Text/Text/TextNonDarwinShims.swift 16.66% 10 Missing ⚠️
Sources/OpenSwiftUI/Util/OpenSwiftUIGlue.swift 0.00% 3 Missing ⚠️
...SwiftUICore/View/Text/Text/TextUnimplemented.swift 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #892      +/-   ##
==========================================
- Coverage   26.77%   26.68%   -0.09%     
==========================================
  Files         690      693       +3     
  Lines       48287    48651     +364     
==========================================
+ Hits        12929    12984      +55     
- Misses      35358    35667     +309     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Kyle-Ye
Kyle-Ye marked this pull request as ready for review June 7, 2026 07:47
@augmentcode

augmentcode Bot commented Jun 7, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR adds foundational support for attributed-string-backed Text rendering and introduces a logical text scaling API.

Changes:

  • Added Text initializer for AttributedString backed by a new AttributedStringTextStorage.
  • Introduced AttributeScopes.OpenSwiftUIAttributes and a set of OpenSwiftUI-specific attributed string keys (font, colors, underline/strikethrough styles, tracking/kern, baseline offset, text scale, etc.).
  • Implemented conversion utilities to merge OpenSwiftUI styles/modifiers into a platform NSAttributedString, including redaction and locale-based case conversion.
  • Added Darwin/non-Darwin shims for inline presentation intent and related NSAttributedString.Key values to support Linux attributed strings.
  • Extended localized formatting/inflection logic to preserve attributed-string styling through token substitution on Darwin.
  • Added Text.Scale and textScale APIs for both Text and View, plus unit tests.

Technical Notes: The implementation relies on attribute transfer/merging during NSAttributedString conversion and adds new resolved-text property hooks (e.g., scale, superscript, custom attributes) to support these features.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

options: Text.ResolveOptions,
properties: inout Text.ResolvedProperties
) {
enumerateAttributes(

@augmentcode augmentcode Bot Jun 7, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sources/OpenSwiftUICore/View/Text/AttributedString/Text+AttributedString.swift:542convertToPlatformStyled mutates the same NSMutableAttributedString (setAttributes / replaceCharacters) from inside enumerateAttributes, which is generally unsafe and can lead to skipped ranges or runtime exceptions. This is especially risky because caseConvertedIfNeeded can change the string length, making subsequent range values invalid.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

//

extension Text {
func strikethrough(_ active: Bool = true, action: Color? = nil) -> Text {

@augmentcode augmentcode Bot Jun 7, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sources/OpenSwiftUICore/View/Text/Text/TextUnimplemented.swift:9 — This Text.strikethrough implementation is a silent no-op, so .inlinePresentationIntent(.strikethrough) processing in withInlinePresentationIntent(from:) won’t have any visible effect and could mask missing behavior.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

}
}

class BoldTextModifier: AnyTextModifier {

@augmentcode augmentcode Bot Jun 7, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sources/OpenSwiftUICore/View/Text/Text/TextUnimplemented.swift:14BoldTextModifier / MonospacedTextModifier don’t override modify(style:environment:) or isEqual(to:), so if they’re ever evaluated (e.g., Text equality via .anyTextModifier), they’ll hit AnyTextModifier’s abstract-method trap at runtime.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@Kyle-Ye
Kyle-Ye force-pushed the feature/attribute_scope branch from bfda42d to 2ee5de6 Compare June 7, 2026 07:58
@Kyle-Ye
Kyle-Ye merged commit 681409e into main Jun 7, 2026
7 checks passed
@Kyle-Ye
Kyle-Ye deleted the feature/attribute_scope branch June 7, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: text Text, labels, line style, and text rendering APIs. platform: Linux Linux-specific behavior or support. type: feature New API, behavior, platform support, or user-facing capability.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant