Repository navigation
Added editable attributed strings for Skip Lite - #143
Conversation
|
@fhasse95 You can test & preview the updated Let me know if you have any comments before I merge this one (and then |
|
@tifroz Thanks for the changes. Overall, it works great! 😊 I just noticed one use case that doesn't seem to be supported in SkipFoundation yet: For example, the following code fails in Skip Lite: private var searchHighlightedText: AttributedString {
let searchText = "skip"
var text = AttributedString("Search highlighting in Skip")
if let range = text.range(of: searchText, options: .caseInsensitive) {
text[range].foregroundColor = .accentColor
}
return text
}Would it be possible to add support for |
fhasse95
left a comment
There was a problem hiding this comment.
Thanks for adding case-insensitive search and the additional tests! Looks good to me. Feel free to merge! 👍
|
@fhasse95 Thanks for the review, I will merge this Here is a quick look at what the updated version looks like in Showcase |
RELEASE MANAGEMENT: This PR depends on skiptools/skip-foundation#143 * Added editable attributed text support for Skip Lite * Verified and documented case-insensitive attributed-text highlighting
…les + superscript) Depends on 3 merged PRs - the dependencies are pinned to their respective commit until the next release - [SkipFoundation #143](skiptools/skip-foundation#143) - [SkipUI #597](skiptools/skip-ui#597) - [SkipFuseUI #164](skiptools/skip-fuse-ui#164). * Added attributed text examples using merged Skip dependencies * Added shared attributed-text and search highlighting examples * Listed editable attributed text in the playground index * Avoided Swift type-check timeout in the Alert playground
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Thank you for contributing to the Skip project! Please use this space to describe your change and add any labels (bug, enhancement, documentation, etc.) to help categorize your contribution.
Please review the contribution guide at https://skip.dev/docs/contributing/ for advice and guidance on making high-quality PRs.
Skip Pull Request Checklist:
swift testCodex generated the code, the runtime tested on device from the Showcase app.
Summary
Skip Lite's
AttributedStringcurrently stores text and a Markdown tree, so callers cannot find a range, edit its attributes, or enumerate the resulting runs. This adds an editable subset of Foundation's API for transpiled code.Companion
SkipUI, andShowcasePRs are forthcomingEdit attributes with value semantics
Add
AttributedSubstring,AttributeContainer, inferred ranges, run enumeration, and attribute-preserving append. Range edits split and merge runs while preserving unrelated attributes. Copies and detached substrings remain independent. Equality and hashing include attributes and do not depend on edit history. Named attribute access lets UI libraries add typed properties without introducing a UI dependency into Foundation.Source files:
Sources/SkipFoundation/AttributedString.swiftREADME.mdTests:
Tests/SkipFoundationTests/Formats/EditableAttributedStringTests.swift. Covers overlapping edits and removal, copy independence, substring source coordinates, Unicode ranges, equality/hashing, append, empty values, and writes through array elements. In particular,testCopyAndDetachedSubstringAreIndependentandtestWritesThroughAnArrayElementPreserveValueSemanticscheck transpiled write-back and copying.Make parsed and localized Markdown editable
Create attribute runs from inline Markdown using the existing CommonMark dependency. Preserve whitespace, nested inline styles, and link destinations. Localized substitutions remain literal instead of being parsed again as Markdown. Retain
markdownNodefor existing consumers until the value is edited.Source files:
Sources/SkipFoundation/AttributedString.swiftSources/SkipFoundation/Skip/AttributedMarkdown.ktTests:
Tests/SkipFoundationTests/Formats/EditableAttributedStringTests.swift:testMarkdownCanBeEditedWithoutLosingInlineStyles,testLocalizedInterpolationIsEditable,testLocalizedMarkdownPreservesLiteralPercents, and the Lite-specifictestLocalizedSubstitutionDoesNotIntroduceMarkup.Tests/SkipFoundationTests/Formats/TestMarkdown.swift: eight tests for the existing Markdown tree, including formatting, links, line breaks, interpolation, and percent escaping.Add platform-backed range searching
Both
AttributedStringandAttributedSubstringsupportrange(of:options:locale:). AddString.CompareOptionswith.caseInsensitiveso callers can find"Skip"using"skip"and then edit the returned range.Searches with
.caseInsensitiveor an explicit locale use Android's built-in ICUStringSearch. The returned range uses ICU's matched length in the original text, including when the query and match have different Unicode representations. Substring searches retain their source coordinates. Calls withoptions: []andlocale: nilpreserve the existing exact-match behavior.Source files:
Sources/SkipFoundation/AttributedString.swiftSources/SkipFoundation/String.swiftREADME.mdTests:
EditableAttributedStringTestscovering first-match behavior, missing and empty searches, composed/decomposed accents with different match lengths, substring source coordinates, attribute edits, and an explicit Turkish locale.Usage Example
API Shape
Selected declarations, with implementation omitted:
The same search signature is available on
AttributedSubstring.String.CompareOptionscurrently exposes only.caseInsensitive.Testing
Validation at
f6c1b4f:swift build --build-tests --build-system native.swift test --filter EditableAttributedStringTests: 19 tests against Apple Foundation, zero failures.:SkipFoundation:testDebugUnitTest --tests 'skip.foundation.EditableAttributedStringTests' -Pkotlin.incremental=false: 21 transpiled tests, zero failures or skips.The full package test suite was not run. Generated Kotlin was inspected during implementation to verify substring write-back and detached copying.
Risks / Limitations
[]or.caseInsensitive. Other option flags, including.backwards,.anchored,.diacriticInsensitive, and.regularExpression, are not implemented; unsupported raw option bits fail a precondition rather than being ignored. This does not extend the plainString.range(of:)overload.localeis nil. They support canonical Unicode equivalence and retain accent distinctions under the selected locale's rules. With no options and no locale, search remains exact.StraßewithSTRASSE, while Apple Foundation does. Unicode matching is delegated to the platform; no custom matching tables are added.range(of:)orruns. Lite usesAttributedStringRangeand UTF-16 indices; explicitRange<AttributedString.Index>slicing and partial ranges are unsupported..inlineOnlyPreservingWhitespace, also the Lite default. Block formatting and other parsing modes are unsupported..stringand.descriptionnow contain parsed text without Markdown delimiters; equality and hashing include attributes. Editing invalidates the legacymarkdownNodetree, so renderers must consumerunsto display edited attributes.