Skip to content

Commit

Permalink
Merge pull request #430 from stleamist/bug/byadding-parts-extraattrib…
Browse files Browse the repository at this point in the history
…utes-overriding

Fixes an issue where `byAdding(.extraAttributes(_:))` removes previously assigned `extraAttributes`.
  • Loading branch information
ZevEisenberg authored Jun 12, 2023
2 parents f795ab3 + 90e216b commit becf396
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/StringStyle+Part.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ extension StringStyle {
mutating func update(part stylePart: Part) {
switch stylePart {
case let .extraAttributes(attributes):
self.extraAttributes = attributes
self.add(extraAttributes: attributes)
case let .font(font):
self.font = font
case let .link(link):
Expand Down
9 changes: 9 additions & 0 deletions Tests/AttributedStringStyleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,15 @@ class StringStyleTests: XCTestCase {
BONAssert(attributes: childAttributes, key: .foregroundColor, value: BONColor.black)
}

func testOverridingExtraAttributesPart() {
let style = StringStyle()
.byAdding(.extraAttributes([.backgroundColor: BONColor.white]))
.byAdding(.extraAttributes([.foregroundColor: BONColor.black]))

BONAssert(attributes: style.attributes, key: .backgroundColor, value: BONColor.white)
BONAssert(attributes: style.attributes, key: .foregroundColor, value: BONColor.black)
}

}

private extension StringStyleTests {
Expand Down

0 comments on commit becf396

Please sign in to comment.