Как правильно настроить roundRect backgroundColor для символов в NSTextView? - PullRequest
0 голосов
/ 06 мая 2018

Я хочу настроить 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)
    }
}

и эффект:

enter image description here

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

enter image description here

Я бы хотел, чтобы эффект был: enter image description here

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

и мой проект здесь: github

...