danielsaidi / RichTextKit

RichTextKit is a Swift SDK that helps you use rich text in Swift and SwiftUI.
MIT License
950 stars 126 forks source link

Calling setAttributedString(to string: NSAttributedString) overrides font size #65

Closed DavidAlvarezDev closed 8 months ago

DavidAlvarezDev commented 1 year ago

Hey Daniel,

Hope your weekend is going well. I have a suggestion for this method.

Is it possible for the string passed to this function not be altered? Maybe I understand the usage of this function incorrectly, but I tried to use it to update my NSAttributedString to a new value after some changes to it, but I noticed the font size would change on the NSAttributedString. It was obvious why after looking at the method.

My workaround was to just set the context.shouldSetAttributedString properly directly in my method to update the editor.

Thanks,

David Alvarez info@davidalvarezdev.com

   /**
     Set the attributed string to a new rich text.

     - Parameters:
       - string: The rich text string to set.
     */
    func setAttributedString(to string: NSAttributedString) {
        let mutable = NSMutableAttributedString(attributedString: string)
        mutable.setFontSize(to: fontSize)
        shouldSetAttributedString = mutable
    }
danielsaidi commented 1 year ago

Great find, I may have added the font size as a fix for a specific situation that I currently can't recall 😅

I will take a look at this.

MrGobert commented 9 months ago

Yeah this is still happening. So when I load my saved notes that have had their font sized changed, it returns to the default size for all text.

DominikBucher12 commented 9 months ago

hello @MrGobert, how do you load your saved notes? Or how do you mean it? Can you please share some examples? The code is long gone from the function just now, so when you call the function you will just get what attributed string you passed.

danielsaidi commented 8 months ago

This was due to a bug in how the rich text view setup its underlying theme. It should work in the main branch now.