Colored bullets NSTextList

I am using NSTextList in a text editor I am creating. I am trying to change the color of the bullets in an NSTextList while still keeping the built-in functionality of the NSTextList. So far, I've tried to override the shouldChangeText function in the NSTextList to intercept when a bullet is added and tried to replace it with my colored bullet.

override func shouldChangeText(in affectedCharRange: NSRange, replacementString: String) {
    if replacementString == "\t\u{2022}\t" {
        let redBullet = NSAttributedString(string: "\t\u{2022}\t", attributes: [NSForegroundColorAttributeName: NSColor.red])
        insertText(redBullet, replacementRange: affectedCharRange)
        return false
    }
}

      

However, this does not preserve the functionality of the NSTextList, nor does it distinguish if the bullet is already colored or not. Any advice on how to do this would be greatly appreciated.

+3


source to share





All Articles