NSTextView's Default Insertion Point and Selected Text Colors

NSTextView can be customized to display different colors for the insertion point (aka caret, aka text cursor) and for selected text. This is especially useful when you add themes to your editor and the default settings don’t fit anymore.

3 theme settings visualized

The default values are not exposed anywhere, so I had to log them and reconstruct convenient accessors to reset a text view if needed:

extension NSTextView {
    static var defaultInsertionPointColor: NSColor { 
        return NSColor.controlTextColor 
    }

    static var defaultSelectedTextAttributes: [NSAttributedStringKey : Any] {
        return [
            .foregroundColor: NSColor.selectedTextColor,
            .backgroundColor: NSColor.selectedTextBackgroundColor
        ]
    }
}