From 806c5ddf295677273ade0e63e3ad501b972e2b1d Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 1 Jul 2022 17:01:39 +0400 Subject: [PATCH] Support animated emoji in caption edit fields. --- .../SourceFiles/boxes/edit_caption_box.cpp | 23 ++++---- Telegram/SourceFiles/boxes/send_files_box.cpp | 27 ++++------ .../chat_helpers/message_field.cpp | 54 ++++++++++--------- .../SourceFiles/chat_helpers/message_field.h | 8 +-- .../SourceFiles/core/click_handler_types.cpp | 8 +-- .../SourceFiles/history/history_widget.cpp | 1 - .../history_view_compose_controls.cpp | 1 - Telegram/lib_ui | 2 +- 8 files changed, 60 insertions(+), 64 deletions(-) diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 4e053be74..47dda849c 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -241,20 +241,19 @@ void EditCaptionBox::rebuildPreview() { } void EditCaptionBox::setupField() { - const auto show = std::make_shared(_controller); - const auto session = &_controller->session(); + InitMessageFieldHandlers( + _controller, + _field.get(), + Window::GifPauseReason::Layer); + Ui::Emoji::SuggestionsController::Init( + getDelegate()->outerContainer(), + _field, + &_controller->session()); + _field->setSubmitSettings( Core::App().settings().sendSubmitWay()); - _field->setInstantReplaces(Ui::InstantReplaces::Default()); - _field->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); - _field->setMarkdownReplacesEnabled(rpl::single(true)); - _field->setEditLinkCallback( - DefaultEditLinkCallback(show, session, _field)); _field->setMaxHeight(st::confirmCaptionArea.heightMax); - InitSpellchecker(show, session, _field); - connect(_field, &Ui::InputField::submitted, [=] { save(); }); connect(_field, &Ui::InputField::cancelled, [=] { closeBox(); }); connect(_field, &Ui::InputField::resized, [=] { captionResized(); }); @@ -273,10 +272,6 @@ void EditCaptionBox::setupField() { } Unexpected("Action in MimeData hook."); }); - Ui::Emoji::SuggestionsController::Init( - getDelegate()->outerContainer(), - _field, - &_controller->session()); auto cursor = _field->textCursor(); cursor.movePosition(QTextCursor::End); diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 63ea695b2..e21a94933 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -672,9 +672,19 @@ void SendFilesBox::updateSendWayControlsVisibility() { } void SendFilesBox::setupCaption() { - _caption->setMaxLength(kMaxMessageLength); + InitMessageFieldHandlers( + _controller, + _caption.data(), + Window::GifPauseReason::Layer); + Ui::Emoji::SuggestionsController::Init( + getDelegate()->outerContainer(), + _caption, + &_controller->session()); + _caption->setSubmitSettings( Core::App().settings().sendSubmitWay()); + _caption->setMaxLength(kMaxMessageLength); + connect(_caption, &Ui::InputField::resized, [=] { captionResized(); }); @@ -696,21 +706,6 @@ void SendFilesBox::setupCaption() { } Unexpected("action in MimeData hook."); }); - const auto show = std::make_shared(_controller); - const auto session = &_controller->session(); - - _caption->setInstantReplaces(Ui::InstantReplaces::Default()); - _caption->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); - _caption->setMarkdownReplacesEnabled(rpl::single(true)); - _caption->setEditLinkCallback( - DefaultEditLinkCallback(show, session, _caption)); - Ui::Emoji::SuggestionsController::Init( - getDelegate()->outerContainer(), - _caption, - session); - - InitSpellchecker(show, session, _caption); updateCaptionPlaceholder(); setupEmojiPanel(); diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 3194d84b6..c213f062f 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -286,12 +286,12 @@ Fn controller, - not_null field) { - field->setMinHeight( - st::historySendSize.height() - 2 * st::historySendPadding); - field->setMaxHeight(st::historyComposeFieldMaxHeight); + not_null field, + Window::GifPauseReason pauseReasonLevel) { + const auto show = std::make_shared(controller); + const auto session = &controller->session(); field->setTagMimeProcessor(FieldTagMimeProcessor(controller)); field->setCustomEmojiFactory([=](QStringView data, Fn update) { @@ -299,23 +299,36 @@ void InitMessageField( data, std::move(update)); }, [=] { - return controller->isGifPausedAtLeastFor( - Window::GifPauseReason::Any); + return controller->isGifPausedAtLeastFor(pauseReasonLevel); }); - - field->document()->setDocumentMargin(4.); - field->setAdditionalMargin(style::ConvertScale(4) - 4); - - field->customTab(true); field->setInstantReplaces(Ui::InstantReplaces::Default()); field->setInstantReplacesEnabled( Core::App().settings().replaceEmojiValue()); field->setMarkdownReplacesEnabled(rpl::single(true)); field->setEditLinkCallback( - DefaultEditLinkCallback( - std::make_shared(controller), - &controller->session(), - field)); + DefaultEditLinkCallback(show, session, field)); + + InitSpellchecker( + std::make_shared(controller), + session, + field); +} + +void InitMessageFieldGeometry(not_null field) { + field->setMinHeight( + st::historySendSize.height() - 2 * st::historySendPadding); + field->setMaxHeight(st::historyComposeFieldMaxHeight); + + field->document()->setDocumentMargin(4.); + field->setAdditionalMargin(style::ConvertScale(4) - 4); +} + +void InitMessageField( + not_null controller, + not_null field) { + InitMessageFieldHandlers(controller, field, Window::GifPauseReason::Any); + InitMessageFieldGeometry(field); + field->customTab(true); } void InitSpellchecker( @@ -339,15 +352,6 @@ void InitSpellchecker( #endif // TDESKTOP_DISABLE_SPELLCHECK } -void InitSpellchecker( - not_null controller, - not_null field) { - InitSpellchecker( - std::make_shared(controller), - &controller->session(), - field); -} - bool HasSendText(not_null field) { const auto &text = field->getTextWithTags().text; for (const auto &ch : text) { diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index 01f4f6dae..ca4472750 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -24,6 +24,7 @@ class Session; namespace Window { class SessionController; +enum class GifPauseReason; } // namespace Window namespace Ui { @@ -43,6 +44,10 @@ Fn session, not_null field, const style::InputField *fieldStyle = nullptr); +void InitMessageFieldHandlers( + not_null controller, + not_null field, + Window::GifPauseReason pauseReasonLevel); void InitMessageField( not_null controller, not_null field); @@ -52,9 +57,6 @@ void InitSpellchecker( not_null session, not_null field, bool skipDictionariesManager = false); -void InitSpellchecker( - not_null controller, - not_null field); bool HasSendText(not_null field); diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index 255fd1faf..5c0c361d7 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -221,9 +221,11 @@ void MentionNameClickHandler::onClick(ClickContext context) const { } auto MentionNameClickHandler::getTextEntity() const -> TextEntity { - const auto data = QString::number(_userId.bare) - + '.' - + QString::number(_accessHash); + const auto data = TextUtilities::MentionNameDataFromFields({ + .selfId = _session->userId().bare, + .userId = _userId.bare, + .accessHash = _accessHash, + }); return { EntityType::MentionName, data }; } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 62a372048..271c35d40 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -473,7 +473,6 @@ HistoryWidget::HistoryWidget( } Unexpected("action in MimeData hook."); }); - InitSpellchecker(controller, _field); const auto suggestions = Ui::Emoji::SuggestionsController::Init( this, 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 5e42b6ba3..da4d23433 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1426,7 +1426,6 @@ void ComposeControls::initField() { _field, &_window->session()); _raiseEmojiSuggestions = [=] { suggestions->raise(); }; - InitSpellchecker(_window, _field); const auto rawTextEdit = _field->rawTextEdit().get(); rpl::merge( diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 6bd751810..0b829240f 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 6bd7518109850d650a174b74e5582367555390da +Subproject commit 0b829240fd3ade757aa4e957c17d84a81ef1c3ff