From da18b6125155a45d3d3a2ae398e47add11370653 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 18 May 2026 22:23:00 +0300 Subject: [PATCH] Added ability to switch filters in share and forward boxes with hotkey. --- Telegram/SourceFiles/boxes/share_box.cpp | 5 +++- .../ui/widgets/chat_filters_tabs_slider.h | 3 +++ .../ui/widgets/chat_filters_tabs_strip.cpp | 24 ++++++++++++++++++- .../ui/widgets/chat_filters_tabs_strip.h | 3 ++- .../SourceFiles/window/window_peer_menu.cpp | 5 +++- .../window/window_session_controller.cpp | 3 ++- 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 1cbf028752..c66da6a6f9 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -366,7 +366,10 @@ void ShareBox::prepare() { _inner->applyChatFilter(id); scrollToY(0); }, - Window::GifPauseReason::Layer); + Window::GifPauseReason::Layer, + nullptr, + false, + true); chatsFilters->lower(); chatsFilters->heightValue() | rpl::on_next([this](int h) { updateScrollSkips(); diff --git a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.h b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.h index 1375b70dcd..3e4ace259a 100644 --- a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.h +++ b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.h @@ -35,6 +35,9 @@ public: void fitWidthToSections() override; void setUnreadCount(int index, int unreadCount, bool muted); void setLockedFrom(int index); + [[nodiscard]] int lockedFrom() const { + return _lockedFrom; + } [[nodiscard]] rpl::producer contextMenuRequested() const; [[nodiscard]] rpl::producer<> lockedClicked() const; diff --git a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp index 001d7a9a9e..39f7e45009 100644 --- a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp +++ b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/filters/edit_filter_box.h" #include "boxes/premium_limits_box.h" #include "core/application.h" +#include "core/shortcuts.h" #include "core/ui_integration.h" #include "data/data_chat_filters.h" #include "data/data_peer_values.h" // Data::AmPremiumValue. @@ -204,7 +205,8 @@ not_null AddChatFiltersTabsStrip( Fn choose, ChatHelpers::PauseReason pauseLevel, Window::SessionController *controller, - bool trackActiveFilterAndUnreadAndReorder) { + bool trackActiveFilterAndUnreadAndReorder, + bool handleKeyboardSwitch) { const auto wrap = Ui::CreateChild>( parent, @@ -523,6 +525,26 @@ not_null AddChatFiltersTabsStrip( wrap->resize(w, h); }, wrap->lifetime()); + if (handleKeyboardSwitch) { + Shortcuts::ChatSwitchRequests( + ) | rpl::filter([=](const Shortcuts::ChatSwitchRequest &request) { + return wrap->toggled() + && ((request.action == Qt::Key_Tab) + || (request.action == Qt::Key_Backtab)); + }) | rpl::on_next([=](const Shortcuts::ChatSwitchRequest &request) { + const auto count = slider->sectionsCount(); + const auto locked = slider->lockedFrom(); + const auto limit = locked ? locked : count; + if (limit <= 1) { + return; + } + const auto back = (request.action == Qt::Key_Backtab); + const auto current = std::min(slider->activeSection(), limit - 1); + const auto next = (current + (back ? -1 : 1) + limit) % limit; + slider->setActiveSection(next); + }, wrap->lifetime()); + } + return wrap; } diff --git a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.h b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.h index 9cbc79f22f..79165515dc 100644 --- a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.h +++ b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.h @@ -31,6 +31,7 @@ not_null AddChatFiltersTabsStrip( Fn choose, ChatHelpers::PauseReason pauseLevel, Window::SessionController *controller = nullptr, - bool trackActiveFilterAndUnreadAndReorder = false); + bool trackActiveFilterAndUnreadAndReorder = false, + bool handleKeyboardSwitch = false); } // namespace Ui diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index e34c5f661f..5622117c1d 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -3052,7 +3052,10 @@ base::weak_qptr ShowForwardMessagesBox( *lastFilterId = id; applyFilter(box, id); }, - Window::GifPauseReason::Layer); + Window::GifPauseReason::Layer, + nullptr, + false, + true); chatsFilters->lower(); rpl::combine( chatsFilters->heightValue(), diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 5b3484e156..7a283f5723 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1901,7 +1901,8 @@ void SessionController::setupShortcuts() { return !window().locked() && (_chatSwitchProcess || (request.started - && (Core::App().activeWindow() == &window()))); + && (Core::App().activeWindow() == &window()) + && !isLayerShown())); }) | rpl::on_next([=](const ChatSwitchRequest &request) { if (!_chatSwitchProcess) { _chatSwitchProcess = std::make_unique(