UnigramDev/Unigram/highlight-quote-mismatch • ae11bc5 • 2 files, +14/-1
Only locate a quote in the text the bubble actually rendered
MessageBubble.Highlight walks message.Text.Paragraphs and asks Message for the
block rendering each one, pairing an index into the model with an index into
the view. Nothing guaranteed the two describe the same text, and GetBlock
returns null when no range covers the index, so the paragraph dereference a few
lines later threw.
MessageAnimatedEmoji is the deterministic case. The message is a plain text
message that TDLib re-types in the API layer, so it is quotable everywhere and
the quote rides on the replying message; searchQuote compares text only and
GetCaption returns the emoji, so the quote always matches. But UpdateMessageText
excludes it from SetText and Recycle clears the ranges, so every GetBlock is
null. A translation or a summary reaches the same state differently: it is an
independent StyledText, and since entities are dropped in translation a
blockquote that forced a paragraph break in the original no longer does, so the
rendered text can have fewer paragraphs than the model.
Compare the two by reference before entering the branch, rather than guarding
the null it produces. The null only appears when the paragraph counts differ;
when they happen to match but the content does not, the old code drew the
highlight in the wrong places instead of crashing, and that is silent. Falling
back to the whole-bubble rect is also the right visual: content that never
reaches SetText is drawn by Media, which the fallback already targets.
Reported by crash telemetry on 12.9.1.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
#unigram
Post #20652
64