The goal of this project is to build NSTextView replacement component utilizing TextKit2. Because reasons.
The component is developed to serve Swift Studio needs. (ST prefix stands for "Swift sTudio" because SS is not good prefix since 1939)
Screen.Recording.2022-02-25.at.11.51.41.mov
TextKit2 was announced during WWDC 2021 as a TextKit replacement for text layout and whatnot. Apple announced that NSTextView
, the view component specialized for text editing, will adopt TextKit2 and provide support along TextKit1 bits. As I started to learn more about NSTextView
+ TextKit2, I realized as of today (Feb 2022), neither NSTextView is fully functional, nor TextKit2 classes are fully functional. Along the way, I reported several bug reports to Apple requested DTS (support tickets). Eventually, I've got blocked by specific bugs that pushed me to start this project.
List of issues I reported so far:
- FB9856587: TextKit2 unexpected additional line fragment for last line
- FB9925766: NSTextSelectionNavigation.deletionRanges only works at the end of the word
- FB9925647: NSTextLayoutManager.replaceContents(in range: with attributedString:) is documented but is not part of the public API
- FB9907261: NSTextElementProvider.replaceContents(in:with:) does not replace content as documented
- FB9692714: Rendering attributes does not draw properly
- FB9886911: NSTextView can't properly layout and display long lines (this one is nasty since it causes the view "jump" whenever text attribute updates)
- FB9713415: NSTextView drawInsertionPoint(in:color:turnedOn) is never called
... I'm aware that the list of issues is not complete.
Swift Package Manager:
dependencies: [
.package(url: "https://github.com/krzyzanowskim/STTextView")
]
let textView = STTextView()
let paragraph = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
paragraph.lineHeightMultiple = 1.1
paragraph.defaultTabInterval = 28
textView.defaultParagraphStyle = paragraph
textView.font = NSFont.monospacedSystemFont(ofSize: 14, weight: .regular)
textView.textColor = .textColor
textView.string = "text content"
textView.addAttributes([.foregroundColor: NSColor.red], range: NSRange(location: 10, length: 5))
textView.widthTracksTextView = true
textView.delegate = self
I'd love to hear from you! Get in touch via twitter @krzyzanowskim, an issue, or a pull request.