-
Notifications
You must be signed in to change notification settings - Fork 253
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
[SuperEditor][AttributedText] Fix placeholder breaking attribution behavior (Resolves #2565) #2566
[SuperEditor][AttributedText] Fix placeholder breaking attribution behavior (Resolves #2565) #2566
Conversation
…havior (Resolves #2565)
The golden test suites are automatically failing due to this error: This request has been automatically failed because it uses a deprecated version of I already updated the version in #2562, but I can update it here if needed. |
// Note: -1 because copyText() uses an exclusive `start` and `end` but | ||
// _copyAttributionRegion() uses an inclusive `start` and `end`. | ||
final startCopyOffset = startOffset < _text.length ? startOffset : _text.length - 1; | ||
int endCopyOffset; | ||
final spansStartCopyOffset = |
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.
It's not clear to me why we're creating new start and end offsets. Why aren't the existing start and end offsets correct? Also what does "spans" mean?
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.
It's not clear to me why we're creating new start and end offsets. Why aren't the existing start and end offsets correct?
Because of the comment above, we need to adjust the offsets to make them inclusive. But I do agree that is not clear why the startCopyOffset could be greater than the text length.
Also what does "spans" mean?
Maybe it would be better to call this attributionStartCopyOffset
, because this offset is passed to AttributedSpans.copyAttributionRegion
to copy the attributions in the range.
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.
Because of the comment above, we need to adjust the offsets to make them inclusive
Looking closer, was the existing variable just renamed? If so, I'm not sure that it needed a new name. Let me know if I'm missing something.
Could this PR be reduced to simply adding final textWithPlaceholders = toPlainText();
and using that instead of _text
?
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.
Yeah, I was trying to make the variable name more clear, but I reverted the variable rename.
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.
LGTM
[SuperEditor][AttributedText] Fix placeholder breaking attribution behavior (Resolves #2565)
Inserting an empty text with a placeholder, with an attribution around it, causes the editor to crash when trying to type.
The issue lives in
AttributedText.copyText
:We are using the text without placeholders to determine the starting offset to copy the spans, but the span marker offsets are based on the text with the placeholders.
The current implementation causes the
startCopyOffset
to be-1
. This causes an issue inAttributedSpans.copyAttributionRegion
, in the following code:The expression
marker.offset - startOffset
evaluates to0 - (-1) = 1
. The span marker should be at offset 0, and we are changing it to offset 1. This is the cause of the exception.This PR fixes this issue by computing the start and end offset of the span copy to be based on the text with placeholders.