danielsaidi / RichTextKit

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

NSAttributedString not updating when style changes and text is highlighted #190

Open MatthewWaller opened 2 weeks ago

MatthewWaller commented 2 weeks ago

Hello. I have a setup where the I highlight some text in the RichTextEditor, and then make it bold. I'm listening for changes to the attributedString, and if there is a change, I persist it.

Here are the steps and issue I'm seeing. I'm on 1.0.0, on iOS.

  1. Use RichTextEditor to write some text.
  2. Listen for changes to the attributedString with onChange(context.attributedString
  3. Select a range of text.
  4. Use RichTextKeyboardToolbar to make the text bold.
  5. Notice that the text is bold and onChange did not fire.
  6. Deselect the text.
  7. Notice now that the onChange method did fire.

Expected result:

Any work arounds?

danielsaidi commented 1 week ago

Hi @MatthewWaller

Thank you for reporting this.

I think the reason to why this doesn't work is that (if I remember correctly) the text binging is not updated continuously, since it would cause the text editor to redraw. Instead, it's synced at certain points.

I'm currently swamped with other projects, but I'll revisit this once iOS 18 is out. My idea is to actually change the text binding at all times, but have a second decoupled text binding that is bound to the editor.