From c535a7c5646653aee826b26d874d4d84a66f4c77 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 25 Sep 2020 14:12:36 +0300 Subject: [PATCH] Use MaskedInputField for URL input. --- .../chat_helpers/message_field.cpp | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 347cfb9a55..33f7f12f2f 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -150,13 +150,26 @@ void EditLinkBox::prepare() { session); InitSpellchecker(_controller, text); - const auto url = content->add( - object_ptr( + const auto placeholder = content->add( + object_ptr(content), + st::markdownLinkFieldPadding); + placeholder->setAttribute(Qt::WA_TransparentForMouseEvents); + const auto url = Ui::AttachParentChild( + content, + object_ptr( content, st::defaultInputField, tr::lng_formatting_link_url(), - _startLink.trimmed()), - st::markdownLinkFieldPadding); + _startLink.trimmed())); + url->heightValue( + ) | rpl::start_with_next([placeholder](int height) { + placeholder->resize(placeholder->width(), height); + }, placeholder->lifetime()); + placeholder->widthValue( + ) | rpl::start_with_next([=](int width) { + url->resize(width, url->height()); + }, placeholder->lifetime()); + url->move(placeholder->pos()); const auto submit = [=] { const auto linkText = text->getLastText(); @@ -178,7 +191,7 @@ void EditLinkBox::prepare() { connect(text, &Ui::InputField::submitted, [=] { url->setFocusFast(); }); - connect(url, &Ui::InputField::submitted, [=] { + connect(url, &Ui::MaskedInputField::submitted, [=] { if (text->getLastText().isEmpty()) { text->setFocusFast(); } else { @@ -198,7 +211,11 @@ void EditLinkBox::prepare() { setDimensions(st::boxWidth, content->height()); _setInnerFocus = [=] { - (_startText.isEmpty() ? text : url)->setFocusFast(); + if (_startText.isEmpty()) { + text->setFocusFast(); + } else { + url->setFocusFast(); + } }; }