diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index 9e290988f9..824f7816b2 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "ui/boxes/confirm_box.h" #include "ui/toast/toast.h" +#include "ui/widgets/popup_menu.h" #include "base/qthelp_regex.h" #include "base/qt/qt_key_modifiers.h" #include "storage/storage_account.h" @@ -33,6 +34,31 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { +[[nodiscard]] TextWithEntities BoldDomainInUrl(const QString &url) { + auto result = TextWithEntities{ .text = url }; + + if (const auto parsedUrl = QUrl(url); parsedUrl.isValid()) { + if (const auto host = parsedUrl.host(); !host.isEmpty()) { + if (const auto hostPos = url.indexOf(host); hostPos != -1) { + auto boldEntity = EntityInText( + EntityType::Bold, + hostPos, + host.length()); + + if (host.startsWith("www.")) { + boldEntity = EntityInText( + EntityType::Bold, + hostPos + 4, + host.length() - 4); + } + + result.entities.push_back(boldEntity); + } + } + } + return result; +} + // Possible context owners: media viewer, profile, history widget. void SearchByHashtag(ClickContext context, const QString &tag) { @@ -155,7 +181,39 @@ void HiddenUrlClickHandler::Open(QString url, QVariant context) { : st::boxLabel; box->addSkip(st.style.lineHeight - st::boxPadding.bottom()); const auto url = box->addRow( - object_ptr(box, displayUrl, st)); + object_ptr( + box, + rpl::single(BoldDomainInUrl(displayUrl)), + st)); + url->setContextMenuHook([=]( + Ui::FlatLabel::ContextMenuRequest request) { + const auto copyContextText = [=] { + TextUtilities::SetClipboardText( + TextForMimeData::Simple(displayUrl)); + }; + if (request.fullSelection) { + request.menu->addAction( + tr::lng_context_copy_link(tr::now), + copyContextText); + } else if (request.uponSelection + && !request.fullSelection) { + const auto selection = request.selection; + const auto copySelectedText = [=] { + TextUtilities::SetClipboardText( + TextForMimeData::Simple( + displayUrl.mid( + selection.from, + selection.to - selection.from))); + }; + request.menu->addAction( + tr::lng_context_copy_selected(tr::now), + copySelectedText); + } else if (request.selection.empty()) { + request.menu->addAction( + tr::lng_context_copy_link(tr::now), + copyContextText); + } + }); url->setSelectable(true); url->setContextCopyText(tr::lng_context_copy_link(tr::now)); });