Character-only mutations should not overwrite paragraph-bound attributes in paragraph following mutation #1302
+39
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When mutating text in an AttributedString that contains paragraph-bound attributes we fix-up the attributes post-mutation by looking at the paragraphs surrounding the mutation. There are up to two applicable paragraphs: one that begins before the mutation and ends somewhere within the mutation (the "starting" paragraph), and one that begins within the mutation and ends after the mutation (the "ending" paragraph). These may be the same paragraph (when the mutation is in the middle of the paragraph), or one or the other may not exist (if the mutation is at the start or the end of a paragraph).
Today, when the mutation is a character-based mutation (i.e. not just setting an attribute value) we always take the attributes from the beginning of the starting paragraph and apply them to the portion that extends into the mutation, and apply the attributes from the beginning of the ending paragraph (within the mutation) and apply them to the rest of the ending paragraph outside the mutation. This is correct for
AttributedString
based replacements (inserting anAttributedString
into anotherAttributedString
) but this isn't quite right for character based replacements (via the character view) where no attributes are supplied. Instead of the inferred attributes of the newly inserted text overwriting the ending paragraph, we should use the attributes from the existing ending paragraph in the inserted/mutated text. This mainly impacts when characters are inserted or mutated at the start of a paragraph and ensures it has the same behavior as when text is inserted anywhere else in the paragraph.