diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 7495f8d95..af1f8979c 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -333,14 +333,9 @@ auto ListWidget::Section::findItemByPoint( Expects(!_items.empty()); if (!_mosaic.empty()) { const auto found = _mosaic.findByPoint(point); - if (found.item) { - const auto rect = findItemRect(found.item); - return { found.item, rect, rect.contains(point) }; - } else { - auto item = (_items.end() - 1)->second; - const auto rect = findItemRect(item); - return { item, rect, rect.contains(point) }; - } + Assert(found.item != nullptr); + const auto rect = findItemRect(found.item); + return { found.item, rect, found.exact }; } auto itemIt = findItemAfterTop(point.y()); if (itemIt == _items.end()) { diff --git a/Telegram/SourceFiles/overview/overview_mosaic_layout.cpp b/Telegram/SourceFiles/overview/overview_mosaic_layout.cpp index f9ec8eee4..351e4051c 100644 --- a/Telegram/SourceFiles/overview/overview_mosaic_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_mosaic_layout.cpp @@ -274,6 +274,7 @@ MosaicLayout::FoundItem MosaicLayout::findByPoint( auto row = -1; auto col = -1; auto sel = -1; + bool exact = true; ClickHandlerPtr link; ItemBase *item = nullptr; if (sy >= 0) { @@ -285,6 +286,17 @@ MosaicLayout::FoundItem MosaicLayout::findByPoint( } sy -= rowHeight; } + } else { + row = 0; + exact = false; + } + if (row >= rowsCount()) { + row = rowsCount() - 1; + exact = false; + } + if (sx < 0) { + sx = 0; + exact = false; } if (sx >= 0 && row >= 0 && row < rowsCount()) { const auto columnsCount = _rows[row].items.size(); @@ -298,18 +310,18 @@ MosaicLayout::FoundItem MosaicLayout::findByPoint( sx -= width; sx -= _rightSkip; } - if (col < columnsCount) { - item = itemAt(row, col); - sel = ::Layout::PositionToIndex(row, + col); - const auto result = item->getState(QPoint(sx, sy), {}); - link = result.link; - } else { - row = col = -1; + if (col >= columnsCount) { + col = columnsCount - 1; + exact = false; } + item = itemAt(row, col); + sel = ::Layout::PositionToIndex(row, + col); + const auto result = item->getState(QPoint(sx, sy), {}); + link = result.link; } else { row = col = -1; } - return { link, item, sel }; + return { link, item, sel, exact }; } } // namespace Overview::Layout diff --git a/Telegram/SourceFiles/overview/overview_mosaic_layout.h b/Telegram/SourceFiles/overview/overview_mosaic_layout.h index de67339ec..c58dbd9be 100644 --- a/Telegram/SourceFiles/overview/overview_mosaic_layout.h +++ b/Telegram/SourceFiles/overview/overview_mosaic_layout.h @@ -17,6 +17,7 @@ public: ClickHandlerPtr link; ItemBase *item = nullptr; int index = -1; + bool exact = false; }; MosaicLayout();