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

[BUGFIX Fix Alignment setting #131

Merged
merged 3 commits into from
Jan 24, 2024
Merged

[BUGFIX Fix Alignment setting #131

merged 3 commits into from
Jan 24, 2024

Conversation

DominikBucher12
Copy link
Collaborator

@DominikBucher12 DominikBucher12 commented Jan 24, 2024

What this PR do:

  • Fixes alignment setting so now you can set alignment to each line independently :)

How to test it

  • Run app try to mimc same behaviour as in the video or some more.

Where you can start

  • If the tests are running, you are fine :)
alignment.mov

@DominikBucher12
Copy link
Collaborator Author

Screenshot 2024-01-24 at 12 55 59

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

// The cursor is at the beginning of the text
if range.location == 0 {
return setAlignment(alignment, atIndex: 0)
}

// The cursor is immediately after a newline
if let char = text.character(at: range.location - 1), char.isNewLineSeparator {
return setAlignment(alignment, atIndex: range.location)
// We dont want to set attributed string to previous line,
// isNewLineSeparator is unfortunately omitted by API.
Copy link
Collaborator Author

@DominikBucher12 DominikBucher12 Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielsaidi this was main reason the line above were being aligned as well as the current line.

@DominikBucher12 DominikBucher12 marked this pull request as ready for review January 24, 2024 14:10
@DominikBucher12 DominikBucher12 changed the title [WIP] Fix Alignment [BUGFIX Fix Alignment setting Jan 24, 2024
@danielsaidi danielsaidi changed the base branch from main to paragraph-fix January 24, 2024 22:01
@danielsaidi
Copy link
Owner

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

@danielsaidi danielsaidi merged commit 2f2acee into paragraph-fix Jan 24, 2024
1 check passed
@danielsaidi
Copy link
Owner

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

@danielsaidi
Copy link
Owner

Skarminspelning.2024-01-24.kl.23.08.03.mov

@danielsaidi
Copy link
Owner

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

@danielsaidi
Copy link
Owner

@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
Copy link
Owner

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.

@danielsaidi danielsaidi deleted the bugfix/paragraphs branch February 14, 2024 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants