I have the same issue about the paragraph spacing for the fragments. It looks like the NSParagraphStyle does not works for TextKit 2.
Finally, I use a new subclass for NSTextLayoutFragment and override the bottomMargin to the spacing.
extension TextAreaView: NSTextLayoutManagerDelegate {
func textLayoutManager(_ textLayoutManager: NSTextLayoutManager, textLayoutFragmentFor location: NSTextLocation, in textElement: NSTextElement) -> NSTextLayoutFragment {
let endTextLocation = textLayoutManager.documentRange.endLocation
if let elementRangeEndLocation = textElement.elementRange?.endLocation,
elementRangeEndLocation.compare(endTextLocation) == .orderedSame {
return NSTextLayoutFragment(textElement: textElement, range: textElement.elementRange)
} else {
return ParagraphTextLayoutFragment(textElement: textElement, range: textElement.elementRange)
}
}
}
Maybe we could add some view during surfacing drawing due to the NSTextLayoutFragment could be customized by subclassing. I'm working on adding a custom view inline. And still needs some efforts.