Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighting Style Not Applied in RichTextEditor #195

Open
alelordelo opened this issue Sep 24, 2024 · 1 comment
Open

Highlighting Style Not Applied in RichTextEditor #195

alelordelo opened this issue Sep 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@alelordelo
Copy link

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

  1. Create a RichTextHighlightingStyle with a custom foreground color (e.g., red).
  2. Pass this style to the RichTextEditor in a SwiftUI view.
  3. 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.

@danielsaidi
Copy link
Owner

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.

@danielsaidi danielsaidi added the bug Something isn't working label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants