Highlighting Style Not Applied in RichTextEditor
Description
I'm encountering an issue where the RichTextHighlightingStyle is not being applied correctly in the RichTextEditor. Despite setting a custom highlighting style, the text remains unhighlighted and the foreground color is not changing as expected.
Steps to Reproduce
- Create a
RichTextHighlightingStylewith a custom foreground color (e.g., red). - Pass this style to the
RichTextEditorin a SwiftUI view. - Attempt to highlight text in the editor.
Expected Behavior
The highlighted text should appear with the custom foreground color (red in this case).
Actual Behavior
The foreground color does not change.
Code Sample
let customHighlightStyle = RichTextHighlightingStyle(
backgroundColor: .yellow.opacity(0.3),
foregroundColor: .red
)
RichTextEditor(
text: $cell.richText,
context: cell.text,
config: editorConfig,
highlightingStyle: customHighlightStyle,
placeholder: cell.textStyle.asAttributedString(),
font: NSFont.systemFont(ofSize: cell.textStyle.size)
) { _ in
cell.text.setAttributedString(to: cell.richText)
}
Additional Context
I've verified that the customHighlightStyle is being created correctly and passed to the RichTextEditor. However, it seems that either the style is not being applied to the underlying NSTextView, or there might be an issue with how the highlighting is implemented.
Possible Related Code
In the RichTextView class, there's a highlightingStyle property and a setupHighlightStyle() method:
class RichTextView: NSTextView, RichTextViewComponent {
var highlightingStyle: RichTextHighlightingStyle = .standard
func setupHighlightStyle() {
self.selectedTextAttributes = [
.backgroundColor: NSColor(highlightingStyle.backgroundColor),
.foregroundColor: NSColor(highlightingStyle.foregroundColor)
]
}
// ...
}
Question
Is there any additional setup required to ensure the highlighting style is applied correctly? Are there any known issues or limitations with custom highlighting styles in the current version of the package?
Any assistance or insights would be greatly appreciated.
Hi @alelordelo
Thank you for the very detailed bug report.
I'm very busy with other projects at the moment, but am planning to revisit this project later. Until then, I'm happy to look at any PR or code that could help fix this.