diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 44ecd112b..3a2e46dde 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -2087,15 +2087,13 @@ auto TrackPanel::FindCell(int mouseX, int mouseY) -> FoundCell { auto range = Cells(); auto &iter = range.first, &end = range.second; - auto prev = iter; while ( iter != end && !(*iter).second.Contains( mouseX, mouseY ) ) - prev = iter++; - if ( iter == end ) - // Default to the background cell, which is always last in the sequence, - // even if it does not contain the point - iter = prev; + ++iter; + if (iter == end) + return {}; + auto found = *iter; return { found.first, diff --git a/src/widgets/Ruler.cpp b/src/widgets/Ruler.cpp index 2a7e25d84..208aab6e2 100644 --- a/src/widgets/Ruler.cpp +++ b/src/widgets/Ruler.cpp @@ -3606,7 +3606,10 @@ auto AdornedRulerPanel::FindCell(int mouseX, int mouseY) -> FoundCell if (mayScrub && mScrubZone.Contains(mouseX, mouseY)) return { mScrubbingCell, mScrubZone }; - return { mQPCell, mInner }; + if (mInner.Contains(mouseX, mouseY)) + return { mQPCell, mInner }; + + return {}; } wxRect AdornedRulerPanel::FindRect(const TrackPanelCell &cell)