Skip to content

Commit

Permalink
Use rendering attributes for highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzanowskim committed Sep 14, 2023
1 parent 6ac4273 commit 7c4b5a1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Sources/NeonPlugin/STTextViewSystemInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,27 @@ class STTextViewSystemInterface: TextSystemInterface {
}

func clearStyle(in range: NSRange) {
textView.removeAttribute(.foregroundColor, range: range)
guard let textRange = NSTextRange(range, in: textView.textContentManager) else {
assertionFailure()
return
}

textView.textLayoutManager.removeRenderingAttribute(.foregroundColor, for: textRange)
if let defaultFont = textView.font {
textView.addAttributes([.font: defaultFont], range: range)
}
}

func applyStyle(to token: Neon.Token) {
guard let attrs = attributeProvider(token) else { return }
textView.addAttributes(attrs, range: token.range)
guard let attrs = attributeProvider(token),
let textRange = NSTextRange(token.range, in: textView.textContentManager)
else {
return
}

for attr in attrs {
textView.textLayoutManager.addRenderingAttribute(attr.key, value: attr.value, for: textRange)
}
}

var length: Int {
Expand Down

0 comments on commit 7c4b5a1

Please sign in to comment.