From 9db2502cd09f81d3b6f100bc9c1b0246a3fb0378 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 16 Jan 2025 10:01:59 +0400 Subject: [PATCH] Preserve formatting when editing links. Fixes #28170. --- .../chat_helpers/message_field.cpp | 23 ++++++++++--------- .../SourceFiles/chat_helpers/message_field.h | 2 +- Telegram/lib_ui | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 9cc3a925a..0177e3bfe 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -123,9 +123,9 @@ constexpr auto kLinkProtocols = { void EditLinkBox( not_null box, std::shared_ptr show, - const QString &startText, + const TextWithTags &startText, const QString &startLink, - Fn callback, + Fn callback, const style::InputField *fieldStyle, Fn validate) { Expects(callback != nullptr); @@ -137,6 +137,7 @@ void EditLinkBox( object_ptr( content, fieldSt, + Ui::InputField::Mode::SingleLine, tr::lng_formatting_link_text(), startText), st::markdownLinkFieldPadding); @@ -181,9 +182,9 @@ void EditLinkBox( url->move(placeholder->pos()); const auto submit = [=] { - const auto linkText = text->getLastText(); + const auto linkText = text->getTextWithTags(); const auto linkUrl = validate(url->getLastText()); - if (linkText.isEmpty()) { + if (linkText.text.isEmpty()) { text->showError(); return; } else if (linkUrl.isEmpty()) { @@ -222,7 +223,7 @@ void EditLinkBox( box->setWidth(st::boxWidth); box->setFocusCallback([=] { - if (startText.isEmpty()) { + if (startText.text.isEmpty()) { text->setFocusFast(); } else { if (!url->empty()) { @@ -383,7 +384,7 @@ bool EditTextChanged( Fn DefaultEditLinkCallback( std::shared_ptr show, @@ -392,14 +393,14 @@ FncommitMarkdownLinkEdit(selection, text, link); } @@ -470,7 +471,7 @@ void InitMessageFieldHandlers(MessageFieldHandlersArgs &&args) { [[nodiscard]] Fn FactcheckEditLinkCallback( std::shared_ptr show, @@ -478,7 +479,7 @@ void InitMessageFieldHandlers(MessageFieldHandlersArgs &&args) { const auto weak = Ui::MakeWeak(field); return [=]( EditLinkSelection selection, - QString text, + TextWithTags text, QString link, EditLinkAction action) { const auto validate = [=](QString url) { @@ -493,7 +494,7 @@ void InitMessageFieldHandlers(MessageFieldHandlersArgs &&args) { if (action == EditLinkAction::Check) { return IsGoodFactcheckUrl(link); } - auto callback = [=](const QString &text, const QString &link) { + auto callback = [=](const TextWithTags &text, const QString &link) { if (const auto strong = weak.data()) { strong->commitMarkdownLinkEdit(selection, text, link); } diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index 0557a8951..15e5f04b6 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -46,7 +46,7 @@ class Show; Fn DefaultEditLinkCallback( std::shared_ptr show, diff --git a/Telegram/lib_ui b/Telegram/lib_ui index e052a8bff..5fbb38cf8 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit e052a8bff00c24d19c12e61b0adeb5fdf18770f0 +Subproject commit 5fbb38cf872f2132b1ad0a564083c498e6cc6f14