danielsaidi / RichTextKit

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

[BUGFIX Fix Alignment setting #131

Closed DominikBucher12 closed 5 months ago

DominikBucher12 commented 5 months ago

What this PR do:

https://github.com/danielsaidi/RichTextKit/assets/17381941/bdc4a5f8-bc34-407c-89b2-769175b4a012

DominikBucher12 commented 5 months ago

Screenshot 2024-01-24 at 12 55 59

Also currently on macOS since no configuration with default font is set yet.

danielsaidi commented 5 months ago

Great job! Merging this to give it a go. 😀

danielsaidi commented 5 months ago

@DominikBucher12 This doesn't work for me, see movie. The same problem on both macOS and iOS.

danielsaidi commented 5 months ago

https://github.com/danielsaidi/RichTextKit/assets/429927/c8840395-3c42-4b3b-8a84-8334afeaa818

danielsaidi commented 5 months ago

If you want to continue to look at this, I merged it to paragraph-fix.

danielsaidi commented 5 months ago

@DominikBucher12 Actually, if I just have this in RichTextViewComponent+Alignment it behaves better than now, at least on macOS:

public extension RichTextViewComponent {

    /// Get the rich text alignment at current range.
    var richTextAlignment: RichTextAlignment? {
        guard let style = richTextParagraphStyle else { return nil }
        return RichTextAlignment(style.alignment)
    }

    /// Set the rich text alignment at current range.
    ///
    /// > Todo: Something's currently off with alignment. It
    /// spils over to other paragraphs when moving the input
    /// cursor and inserting new text.
    func setRichTextAlignment(
        _ alignment: RichTextAlignment
    ) {
        if richTextAlignment == alignment { return }
        setRichTextAlignment(alignment, at: selectedRange)
    }
}
danielsaidi commented 5 months ago

I have pushed a MUCH shorter version of the alignment setter to the new branch. It seems to work pretty well, but please check it out too.