TextKit Overview
TextKit goes back to the NeXT era, before Mac OS X was a thing. After the relatively new Cocoa frameworks for Mac app programming were introduced and introduced the “Cocoa Text System” title, iOS and UIKit stuck with “TextKit”, and in 2021 TextKit 2 returned.
This revolves around everything related to accepting textual user input on the Mac:
-
NSTextViewfor the UI component, -
NSTextStoragefor the processing of text and style changes, -
NSLayoutManagerfor the computation of line and glyph sizes, and for applying styles, -
NSTypesetterfor putting glyphs on the screen.
Even NSTextFields are just reusing a shared NSTextView, called the window’s field editor. It’s everywhere.
- TextKit API docs: describes all core components and, since TextKit 2, comes with sample projects and WWDC links.
- TextKit 2 Introduction (WWDC 2021)
Related Posts on the Blog
NSPopover in NSTextView With Links Is Broken: Accessibility Hierarchy Slowdown
Showing a popover relative to a text view will compute the accessibility hierarchy 3 times per clickable link in the text view; that can get slow real quick.
NSTextView Bypasses performKeyEquivalent Check for Backspace and Option-Backspace
Shortcuts, aka “key equivalents”, are usually handled by views in your vier hierarchy in the same, predicatable way. Except deleting a character or word with backspace in a text view. These two, apparently, short-circuit this mechanism.
We don’t think about this as we write: the blinking cursor tells a useful lie about what the text looks like, so we can work on an abstraction that is about the space between characters, and especially the space after the last character.
Declarative Text Kit: Sketch of an API
I was fed up with writing long procedures to perform markup changes on the fly. This post contains an API that looks like something I would like to use.
ChatGPT: Publish NSTextView Changes to ReSwift, but Also Use a Lamport Clock
Conversation log with ChatGPT.
NSTextView (Plain Text) and the Pasteboard: PasteboardType.string Is Not Handled
How to Fix When Some Text Changes Don't Come with Automatic Undo?
What Do You Get When You Drag and Drop a PNG File From Finder Into an NSTextView?
NSTextView Performance May Degrade for Large Plain Text Documents When usesFontPanel Is Active
Disable NSTextAttachment Action and Sharing Services Menu Drop-Down
NSTextField usesSingleLineMode Stops Working When You Implement NSTextViewDelegate Methods
NSTextView's Default Insertion Point and Selected Text Colors