danielsaidi / RichTextKit

RichTextKit is a Swift SDK that helps you use rich text in Swift and SwiftUI.
MIT License
950 stars 126 forks source link

The set and setCurrent functionality has a lot of duplicated code. #106

Closed danielsaidi closed 9 months ago

danielsaidi commented 10 months ago

There's currently a lot of duplicated code when it comes to setting attributes, styles, etc.

For instance, here's how the RichTextAttributeWriter and RichTextViewComponent handles setting text style:

image

In this case, you can also see ow the writer implementation actually accidentally omits strikethrough, which is a bug.

All this duplicated setX/setCurrentX functionality is also complicated by the fact that some code actually HAS to differ, but having the duplications sure isn't nice.

danielsaidi commented 10 months ago

In the example above, commit 1a67ab796f2231a9d65d22fa65e34f4b6f895e49 makes the two functions reuse more functionality.

danielsaidi commented 9 months ago

I think the library will eventually get rid of the attribute writer, or at least some of its functions. The component can't just use it as is, but also needs to modify the text storage, layout manager, etc. which means that the attribute writer functions aren't used by the library itself, and may therefore not work as intended.

I think it'd then be better to not have the writer at all.