-
Notifications
You must be signed in to change notification settings - Fork 82
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
EditorView.attributedText problem #286
Comments
I have hit a similar problem and I think this is all down to the setter in I have the following code:
When this is called with text (for example) set to the value:
It calls the setter which contains the lines:
And that I think is the source of my problem - this, as it says, clears the text. The moment it does this it invokes textViewDidChangeSelection, which in turn ends up back in my code responding to the selection change. This all happens before the setter assigns the new value in:
Unfortunately my code has operated on the incorrect attributed string. This, I'm afraid, is a bit of a show stopper. |
@easiwriter, I am not sure if I am getting it fully. Just to share some context: this code, as comment states, is added to circumvent the issue of layout in UITextView. Please note that in case of simple text, this issue is not aggravated. However, when you have a large complex document with custom attributes and a lot of attachments, it has some inconsistent behaviour. In absence of this code, if there is some text with some formatting in the textview and then you reset some other text, in some cases, depending on the attributes it yields unexpected results - possibly trying to merge attributes at the same range. Furthermore, I observed that it also resulted in crashes in some specific cases as the layout calculations in that scenario get corrupted with old and new overlap. Getting back to |
also, not sure if this is relevant for you in this case, but you should know that the text is set only when |
I've added a flag which is set before assigning to attributedText such that any call backs to change selection are ignored. The code in the setter now gets to line 527 in the attributedText setter. At the line:
the newValue is correct.
The input text consists of the letter A followed by a newline. The app implements a style mechanism to control formatting. Instead of fiddling with formatting commands the user simply chooses a style from a menu. In the example above the letter A is formatted according to the attributes of LargeTitle. The style name is held as the custom attribute
The second paragraph is set to the body style as shown by its style attribute. This is where things go wrong. The newValue as I said is correct and the alignment of the second paragraph is Alignment Left. I had just changed this paragraph to use the body style. However, the code below at RichTextView line 82 changes the alignment to Alignment Centre.
Here is the text after this method is called
I don't understand what is going on here because there is only one view, the one containing the text. The app only has a single EditorView. I can only assume that the code has somehow used the alignment of the first paragraph. What is really don't understand is this is not new code. It was working OK before I took a rest for a few months, so I don't know if the changes to AttributedText (here and in the calling method) have been made during this period. If so this would account for the problems I'm now having. |
the code you have referenced here:
has noting to do with Over the past few months, I have been making a lot of updates to Proton which are primarily geared towards fixing bugs and performance issues. There may have been a change or a fix to a bug that is now causing a bug in your code or I might have accidentally fixed one bug and introduced another. I think we can do the following here:
Also, there is no code at all in Proton anywhere that changes the alignment of Paragraph to center. The only code around alignment that is there is in regards to the default |
The code gets to line 527 in the setter where it executes richTextView.attributedText = newValue.
The newValue has left alignment set.
After executing this line the alignment is set to centre aligned, as shown in the debugger output.. Something must have reset it. That is why I’m confused because the code it executes, as you say, doesn’t change it. Maybe a callback has got in there?
I will look through the release note.
Best
Keith
… On 3 Mar 2024, at 08:06, Rajdeep Kwatra ***@***.***> wrote:
the code you have referenced here:
override var attributedText: NSAttributedString! {
willSet {
// Remove all attachment subviews else we may run into PRTextStorage "in middle of editing" crash
subviews.filter { $0 is AttachmentContentView }.forEach { $0.removeFromSuperview() }
}
}
has noting to do with attributedText or alignments of paragraph. This is specifically removing subviews added to teh Editor via Attachment. If I understand it correctly, you are not using any attachments so this code should be of no consequence to you.
Over the past few months, I have been making a lot of updates to Proton which are primarily geared towards fixing bugs and performance issues. There may have been a change or a fix to a bug that is now i causing a bug in your code or I might have accidentally fixed one bug and introduced another. I think we can do the following here:
If it helps, please have a look at the Release Notes here <https://github.com/rajdeep/proton/releases> for the time you were not actively developing the app and see if there's something obvious that shows up.
If possible, please create a failing unit test case with your scenario and the expected output. If I have a failing test case, it will be much easier for me to provide a fix or advise if there's something that you may need to do differently.
Also, there is no code at all in Proton anywhere that changes the alignment of Paragraph to center. The only code around alignment that is there is in regards to the default paragraphStyle that you can set on the Editor which is automatically applied if the editor has some content and then entire content is deleted using backspace/select and delete.
—
Reply to this email directly, view it on GitHub <#286 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEUXIA7WQPMQ5EO4OMPRWQTYWLKW5AVCNFSM6AAAAABD4FMPU2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZVGA4DAMZWGQ>.
You are receiving this because you were mentioned.
|
EditorView.attributedText before assignment is:
The new value being assigned has an additional paragraph and is:
After assignment the value is:
For some reason that I cannot work out the alignment in the second paragraph has been changed from left to centre. I'm sure it is obvious, but I can't see it.
The text was updated successfully, but these errors were encountered: