From 8dc53fb50bc5afd4cdd04e17a764ab6331f89696 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 9 Jun 2026 15:57:21 +0300 Subject: [PATCH] Added new shortcut to toggle web page preview in messages field. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/core/shortcuts.cpp | 2 ++ Telegram/SourceFiles/core/shortcuts.h | 1 + .../SourceFiles/history/history_widget.cpp | 11 +++++++++++ .../controls/history_view_compose_controls.cpp | 18 ++++++++++++++++++ .../controls/history_view_compose_controls.h | 1 + .../history_view_webpage_processor.cpp | 1 + .../settings/sections/settings_shortcuts.cpp | 1 + 8 files changed, 36 insertions(+) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 966d63a71a..35310504b5 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -739,6 +739,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_shortcuts_silent_send" = "Silent send"; "lng_shortcuts_schedule" = "Schedule"; "lng_shortcuts_ai_compose_apply" = "Apply AI style to text"; +"lng_shortcuts_toggle_link_preview" = "Toggle link preview"; "lng_shortcuts_read_chat" = "Mark chat as read"; "lng_shortcuts_archive_chat" = "Archive chat"; "lng_shortcuts_media_fullscreen" = "Toggle video fullscreen"; diff --git a/Telegram/SourceFiles/core/shortcuts.cpp b/Telegram/SourceFiles/core/shortcuts.cpp index 4ca872a75e..3f28de9ca6 100644 --- a/Telegram/SourceFiles/core/shortcuts.cpp +++ b/Telegram/SourceFiles/core/shortcuts.cpp @@ -133,6 +133,7 @@ const auto CommandByName = base::flat_map{ { u"message_silently"_q , Command::SendSilentMessage }, { u"message_scheduled"_q , Command::ScheduleMessage }, { u"ai_compose_apply"_q , Command::ComposeAiApplyInPlace }, + { u"toggle_webpage_preview"_q , Command::ToggleWebPagePreview }, { u"media_viewer_video_fullscreen"_q , Command::MediaViewerFullscreen }, { u"show_scheduled"_q , Command::ShowScheduled }, { u"archive_chat"_q , Command::ArchiveChat }, @@ -157,6 +158,7 @@ const base::flat_map &CommandNames() { Command::SendSilentMessage, Command::ScheduleMessage, Command::ComposeAiApplyInPlace, + Command::ToggleWebPagePreview, Command::MediaViewerFullscreen, Command::ShowScheduled, Command::ArchiveChat, diff --git a/Telegram/SourceFiles/core/shortcuts.h b/Telegram/SourceFiles/core/shortcuts.h index 2d6005ee8d..c6e50ec09b 100644 --- a/Telegram/SourceFiles/core/shortcuts.h +++ b/Telegram/SourceFiles/core/shortcuts.h @@ -69,6 +69,7 @@ enum class Command { SendSilentMessage, ScheduleMessage, ComposeAiApplyInPlace, + ToggleWebPagePreview, RecordVoice, RecordRound, diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index af86beeafa..08f1995e6e 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2312,6 +2312,17 @@ void HistoryWidget::setupShortcuts() { triggerAiApplyInPlace(); return true; }); + _preview + && (_previewDrawPreview || _preview->draft().removed) + && request->check(Command::ToggleWebPagePreview, 1) + && request->handle([=] { + if (_previewDrawPreview) { + _preview->apply({ .removed = true }); + } else { + _preview->apply({}, true); + } + return true; + }); if (showRecordButton() && _canSendMessages && _joinChannel->isHidden() diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 2239b1a462..5fd9192bb2 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -3353,6 +3353,18 @@ void ComposeControls::initVoiceRecordBar() { triggerAiApplyInPlace(); return true; }); + _preview + && (_previewShown || _preview->draft().removed) + && request->check(Command::ToggleWebPagePreview, 1) + && request->handle([=] { + if (_previewShown) { + _preview->apply({ .removed = true }); + } else { + _preview->apply({}, true); + } + saveDraftWithTextNow(); + return true; + }); }, _voiceRecordBar->lifetime()); } @@ -4316,6 +4328,7 @@ void ComposeControls::tryProcessKeyInput(not_null e) { void ComposeControls::initWebpageProcess() { if (!_history) { _preview = nullptr; + _previewShown = false; _header->previewUnregister(); return; } @@ -4324,6 +4337,11 @@ void ComposeControls::initWebpageProcess() { _history, _field); + _preview->parsedValue( + ) | rpl::on_next([=](Controls::WebpageParsed parsed) { + _previewShown = !!parsed; + }, _historyLifetime); + _preview->repaintRequests( ) | rpl::on_next(crl::guard(_header.get(), [=] { _header->update(); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h index 607a3a9ee0..294dcb0be4 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h @@ -547,6 +547,7 @@ private: bool _canAddMedia = false; std::unique_ptr _preview; + bool _previewShown = false; rpl::lifetime _historyLifetime; rpl::lifetime _uploaderSubscriptions; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_webpage_processor.cpp b/Telegram/SourceFiles/history/view/controls/history_view_webpage_processor.cpp index feb0a5edf8..644bf21030 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_webpage_processor.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_webpage_processor.cpp @@ -182,6 +182,7 @@ void WebpageResolver::request(const QString &link, bool force) { void WebpageResolver::cancel(const QString &link) { if (_requestLink == link) { _api.request(base::take(_requestId)).cancel(); + _requestLink = QString(); } } diff --git a/Telegram/SourceFiles/settings/sections/settings_shortcuts.cpp b/Telegram/SourceFiles/settings/sections/settings_shortcuts.cpp index 04cebaa577..10debef78d 100644 --- a/Telegram/SourceFiles/settings/sections/settings_shortcuts.cpp +++ b/Telegram/SourceFiles/settings/sections/settings_shortcuts.cpp @@ -111,6 +111,7 @@ struct Labeled { { C::ScheduleMessage, tr::lng_shortcuts_schedule() }, separator, { C::ComposeAiApplyInPlace, tr::lng_shortcuts_ai_compose_apply() }, + { C::ToggleWebPagePreview, tr::lng_shortcuts_toggle_link_preview() }, separator, { C::RecordVoice, tr::lng_shortcuts_record_voice_message() }, { C::RecordRound, tr::lng_shortcuts_record_round_message() },