Skip to content

Commit

Permalink
Update attributest, not rendering attributes to apply font
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzanowskim committed Aug 6, 2024
1 parent 6afdecf commit 1ee2656
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import NeonPlugin
textView.addPlugin(
NeonPlugin(
theme: .default,
language: .go
language: .swift
)
)
```
Expand All @@ -29,7 +29,7 @@ struct ContentView: View {
text: $text,
selection: $selection,
options: [.wrapLines, .highlightSelectedLine],
plugins: [NeonPlugin(theme: .default, language: .go)]
plugins: [NeonPlugin(theme: .default, language: .swift)]
)
.textViewFont(.monospacedDigitSystemFont(ofSize: NSFont.systemFontSize, weight: .regular))
.onAppear {
Expand Down
7 changes: 6 additions & 1 deletion Sources/NeonPlugin/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ public class Coordinator {

// initial parse of the whole content
tsClient.willChangeContent(in: NSRange(textView.textContentManager.documentRange, in: textView.textContentManager))
tsClient.didChangeContent(in: NSRange(textView.textContentManager.documentRange, in: textView.textContentManager), delta: textView.textContentManager.length, limit: textView.textContentManager.length, readHandler: Parser.readFunction(for: textView.textContentManager.attributedString(in: nil)?.string ?? ""), completionHandler: {})
tsClient.didChangeContent(in: NSRange(textView.textContentManager.documentRange, in: textView.textContentManager),
delta: textView.textContentManager.length,
limit: textView.textContentManager.length,
readHandler: Parser.readFunction(for: textView.textContentManager.attributedString(in: nil)?.string ?? ""),
completionHandler: {
})
}

private func tokenProvider(textContentManager: NSTextContentManager) -> Neon.TokenProvider? {
Expand Down
4 changes: 2 additions & 2 deletions Sources/NeonPlugin/STTextViewSystemInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class STTextViewSystemInterface: TextSystemInterface {
return
}

textView.textLayoutManager.removeRenderingAttribute(.foregroundColor, for: textRange)
textView.removeAttribute(.foregroundColor, range: textRange)
if let defaultFont = textView.font {
textView.addAttributes([.font: defaultFont], range: range)
}
Expand All @@ -34,7 +34,7 @@ class STTextViewSystemInterface: TextSystemInterface {
}

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

Expand Down
4 changes: 2 additions & 2 deletions Sources/NeonPlugin/Theme+Default.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ extension Theme {
tokensCustomFontDict: [
"default": NSFont.monospacedSystemFont(ofSize: 0, weight: .regular),
"keyword": NSFont.monospacedSystemFont(ofSize: 0, weight: .bold),
"constructor": NSFont.monospacedSystemFont(ofSize: 0, weight: .bold)

"constructor": NSFont.monospacedSystemFont(ofSize: 0, weight: .bold),
"text.title": NSFont.monospacedSystemFont(ofSize: 0, weight: .bold)
]
)
}
6 changes: 3 additions & 3 deletions Sources/NeonPlugin/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public struct Theme {
}

public var defaultFont: NSFont? {
return tokensCustomFontDict["default"]
tokensCustomFontDict["default"]
}

public var defaultColor: NSColor? {
return color(forToken: "default")
color(forToken: "default")
}

public func color(forToken tokenName: TokenName) -> NSColor? {
return colors.color(forToken: tokenName)
colors.color(forToken: tokenName)
}

public func font(forToken tokenName: TokenName) -> NSFont? {
Expand Down

0 comments on commit 1ee2656

Please sign in to comment.