-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Conversation
// 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. |
There was a problem hiding this comment.
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.
Great job! Merging this to give it a go. 😀 |
@DominikBucher12 This doesn't work for me, see movie. The same problem on both macOS and iOS. |
Skarminspelning.2024-01-24.kl.23.08.03.mov |
If you want to continue to look at this, I merged it to |
@DominikBucher12 Actually, if I just have this in 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)
}
} |
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. |
What this PR do:
How to test it
Where you can start
alignment.mov