Я хочу настроить roundRect backgroundColor для важных символов в NSTextView. Атрибут является «тегом». Я переопределяю функцию fillBackgroundRectArray(_:count:forCharacterRange:color:)
** NSLayoutManager **. код как ниже:
override func fillBackgroundRectArray(_ rectArray: UnsafePointer<NSRect>, count rectCount: Int, forCharacterRange charRange: NSRange, color: NSColor) {
var effectiveRange = NSMakeRange(0, 0)
let attributes = self.textStorage?.attributes(at: charRange.location, effectiveRange: &effectiveRange)
if attributes?.index(forKey: NSAttributedStringKey(rawValue: "tag")) != nil {
let bezierPath = NSBezierPath(roundedRect: rectArray[0], xRadius: 8, yRadius: 8)
bezierPath.fill()
} else {
super.fillBackgroundRectArray(rectArray, count: rectCount, forCharacterRange: charRange, color: color)
}
}
и эффект:

Но когда я редактирую тег ("panic" в "paniddc") "panic", эффект не является моим желанием. эффект:

Я бы хотел, чтобы эффект был:

Я хочу знать, почему? и что я должен сделать, чтобы добиться последнего эффекта при редактировании тега?
и мой проект здесь: github