diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 3bee997aa..3357767db 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -2019,16 +2019,26 @@ int FindViewY(not_null view, uint16 symbol, int yfrom) { auto request = HistoryView::StateRequest(); request.flags = Ui::Text::StateRequest::Flag::LookupSymbol; const auto single = st::messageTextStyle.font->height; + const auto inner = view->innerGeometry(); + const auto origin = inner.topLeft(); + const auto top = 0; + const auto bottom = view->height(); + if (origin.y() < top + || origin.y() + inner.height() > bottom + || inner.height() <= 0) { + return yfrom; + } const auto fory = [&](int y) { - return view->textState(QPoint(0, y), request).symbol; + return view->textState(origin + QPoint(0, y), request).symbol; }; - auto ytill = view->height() - 1; + yfrom = std::max(yfrom - origin.y(), 0); + auto ytill = inner.height() - 1; auto symbolfrom = fory(yfrom); auto symboltill = fory(ytill); if ((yfrom >= ytill) || (symbolfrom >= symbol)) { - return yfrom; + return origin.y() + yfrom; } else if (symboltill <= symbol) { - return ytill; + return origin.y() + ytill; } while (ytill - yfrom >= 2 * single) { const auto middle = (yfrom + ytill) / 2; @@ -2045,7 +2055,7 @@ int FindViewY(not_null view, uint16 symbol, int yfrom) { symboltill = found; } } - return (yfrom + ytill) / 2; + return origin.y() + (yfrom + ytill) / 2; } } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index b7d4e89d2..736f60ed9 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -4299,14 +4299,18 @@ QRect Message::innerGeometry() const { width())); } if (hasBubble()) { - result.translate(0, st::msgPadding.top() + st::mediaInBubbleSkip); + const auto cut = [&](int amount) { + amount = std::min(amount, result.height()); + result.setTop(result.top() + amount); + }; + cut(st::msgPadding.top() + st::mediaInBubbleSkip); if (displayFromName()) { // See paintFromName(). - result.translate(0, st::msgNameFont->height); + cut(st::msgNameFont->height); } if (displayedTopicButton()) { - result.translate(0, st::topicButtonSkip + cut(st::topicButtonSkip + st::topicButtonPadding.top() + st::msgNameFont->height + st::topicButtonPadding.bottom() @@ -4315,13 +4319,13 @@ QRect Message::innerGeometry() const { if (!displayFromName() && !displayForwardedFrom()) { // See paintViaBotIdInfo(). if (data()->Has()) { - result.translate(0, st::msgServiceNameFont->height); + cut(st::msgServiceNameFont->height); } } // Skip displayForwardedFrom() until there are no animations for it. if (const auto reply = Get()) { // See paintReplyInfo(). - result.translate(0, reply->height()); + cut(reply->height()); } } return result;