danielsaidi / RichTextKit

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

Adopt TextKit 2 (Explicitly) #153

Open DominikBucher12 opened 8 months ago

DominikBucher12 commented 8 months ago

We should move out of using NSLayoutManager and NSTextStorage and NSTextContainer in order to adopt TextKit2.

Currently I believe there must be some other fix to lines and style setting to don't than iterating through textStorage (or we can use new NSTextLayoutManager from TextKit 2 to access this)

The issue with TextKit1 is that it doesn't support native bullet points and numbered points with NSTextList API for a very convenient way to handle those.

Let's maybe wrap the NSLayoutManager for iOS 15 and for iOS 16 use NSTextLayoutManager 🆕🆕🆕

danielsaidi commented 1 month ago

I've had discussions about TextKit 2 with people who know a lot about it, and this seems to be quite a mess :(

Not sure if this should be an open ticket, or if we can mix and match TK1 and TK2 to implement different features?

DominikBucher12 commented 1 month ago

or if we can mix and match TK1 and TK2 to implement different features?

Hmm I am not quite sure it works that way Daniel :(

The current only solution is either TK1 or TK2, since when we access some TK1 properties, TextKit will automatically fallback to 1.

Sorry for such long time without any work or comments, I am just buried with lot of other stuff... But we can have some discussion some other time and I might be able to once again do some research and do this integration smoothly.

DominikBucher12 commented 1 month ago

IMHO creating abstraction as I suggested:

Let's maybe wrap the NSLayoutManager (TK1) for iOS 15 and for iOS 16 use NSTextLayoutManager (TK2)

would make most sense, but by the time I will get into this I think no one will support iOS 15 :D :D :D

danielsaidi commented 1 month ago

@DominikBucher12 Would it make sense to use Glyph?

https://github.com/chimeHQ/Glyph

DominikBucher12 commented 1 month ago

This would serve as a great inspiration... I need to take a look into that + it looks just like a bunch of extensions in a similar way we tried with paragraphs...

I think there are more issues than just this (as you remember, we were dealing with paragraph alignment behaving funky because of selected text vs text in some range vs selected line vs carret being at last character vs macOS behaviour)

It would be wise IMHO to go through the code and figure out the behaviour differences between macOS and iOS/iPad OS, its probably not good idea to try to have one code for all platforms with some ifdefs... But again when I have some time I can try take a look at both and properly test the solution...