From a21b6d7416c0899a5622a1c3f6087cbdf0064538 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 2 Nov 2020 11:44:05 +0300 Subject: [PATCH] Fix restoring scroll state with a pinned bar. --- Telegram/SourceFiles/history/history_widget.cpp | 6 +++++- Telegram/SourceFiles/history/history_widget.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index db142d165..11aa0bd02 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -3230,6 +3230,9 @@ void HistoryWidget::doneShow() { } else { handlePendingHistoryUpdate(); } + // If we show pinned bar here, we don't want it to change the + // calculated and prepared scrollTop of the messages history. + _preserveScrollTop = true; preloadHistoryIfNeeded(); updatePinnedViewer(); if (_pinnedBar) { @@ -3237,6 +3240,7 @@ void HistoryWidget::doneShow() { } checkHistoryActivation(); App::wnd()->setInnerFocus(); + _preserveScrollTop = false; } void HistoryWidget::finishAnimating() { @@ -5330,7 +5334,7 @@ void HistoryWidget::checkPinnedBarState() { _pinnedBarHeight = 0; _pinnedBar->heightValue( ) | rpl::start_with_next([=](int height) { - _topDelta = (height - _pinnedBarHeight); + _topDelta = _preserveScrollTop ? 0 : (height - _pinnedBarHeight); _pinnedBarHeight = height; updateHistoryGeometry(); updateControlsGeometry(); diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 7242417fc..b2b1220b4 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -599,6 +599,7 @@ private: std::unique_ptr _pinnedTracker; std::unique_ptr _pinnedBar; int _pinnedBarHeight = 0; + bool _preserveScrollTop = false; FullMsgId _pinnedClickedId; std::optional _minPinnedId;