From 12250676f9b31afe5d89bc2e90cea62f955f4fef Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 9 Jan 2020 20:01:19 +0300 Subject: [PATCH] Added restoring of scroll position after edit items in SendFilesBox. --- Telegram/SourceFiles/boxes/send_files_box.cpp | 11 +++++++++-- Telegram/SourceFiles/boxes/send_files_box.h | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index a7b78b697..da9aea32a 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -1745,18 +1745,24 @@ void SendFilesBox::prepareAlbumPreview() { _list, _sendWay->value())); - addThumbButtonHandlers(); + addThumbButtonHandlers(wrap); _preview = wrap; _albumPreview->show(); setupShadows(wrap, _albumPreview); initPreview(_albumPreview->desiredHeightValue()); + + crl::on_main([=] { + wrap->scrollToY(_lastScrollTop); + _lastScrollTop = 0; + }); } -void SendFilesBox::addThumbButtonHandlers() { +void SendFilesBox::addThumbButtonHandlers(not_null wrap) { _albumPreview->thumbDeleted( ) | rpl::start_with_next([=](auto index) { + _lastScrollTop = wrap->scrollTop(); _list.files.erase(_list.files.begin() + index); applyAlbumOrder(); @@ -1780,6 +1786,7 @@ void SendFilesBox::addThumbButtonHandlers() { _albumPreview->thumbChanged( ) | rpl::start_with_next([=](auto index) { + _lastScrollTop = wrap->scrollTop(); const auto callback = [=](FileDialog::OpenResult &&result) { FileDialogCallback( diff --git a/Telegram/SourceFiles/boxes/send_files_box.h b/Telegram/SourceFiles/boxes/send_files_box.h index f90c38218..956d9d2c9 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.h +++ b/Telegram/SourceFiles/boxes/send_files_box.h @@ -120,7 +120,7 @@ private: void updateControlsGeometry(); void updateCaptionPlaceholder(); - void addThumbButtonHandlers(); + void addThumbButtonHandlers(not_null wrap); bool canAddFiles(not_null data) const; bool addFiles(not_null data); @@ -169,6 +169,8 @@ private: int _albumVideosCount = 0; int _albumPhotosCount = 0; + int _lastScrollTop = 0; + QPointer _send; QPointer _addFileToAlbum;