From dec9de947c99ee3f6376b92b21d551e41aa53156 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sun, 11 Sep 2022 04:01:25 +0300 Subject: [PATCH] [Improvement] Allow non-emoji auto-replaces with emoji replacements disabled --- .../SourceFiles/boxes/add_contact_box.cpp | 8 ++--- .../SourceFiles/boxes/create_poll_box.cpp | 8 ++--- .../SourceFiles/boxes/edit_caption_box.cpp | 4 +-- .../boxes/filters/edit_filter_box.cpp | 5 ++- .../boxes/peers/edit_peer_info_box.cpp | 8 ++--- Telegram/SourceFiles/boxes/send_files_box.cpp | 4 +-- Telegram/SourceFiles/boxes/share_box.cpp | 4 +-- .../chat_helpers/message_field.cpp | 8 ++--- Telegram/SourceFiles/core/core_settings.h | 34 +++++++++++++++++++ .../settings/settings_information.cpp | 4 +-- .../SourceFiles/support/support_helper.cpp | 4 +-- .../window/notifications_manager_default.cpp | 4 +-- 12 files changed, 50 insertions(+), 45 deletions(-) diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index a376ee9c3..c6e8841c1 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -512,9 +512,7 @@ void GroupInfoBox::prepare() { : tr::lng_dlg_new_group_name)(), _initialTitle); _title->setMaxLength(Ui::EditPeer::kMaxGroupChannelTitle); - _title->setInstantReplaces(Ui::InstantReplaces::Default()); - _title->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + _title->setInstantReplaces(Core::App().settings().instantReplacesValue()); Ui::Emoji::SuggestionsController::Init( getDelegate()->outerContainer(), _title, @@ -528,9 +526,7 @@ void GroupInfoBox::prepare() { tr::lng_create_group_description()); _description->show(); _description->setMaxLength(Ui::EditPeer::kMaxChannelDescription); - _description->setInstantReplaces(Ui::InstantReplaces::Default()); - _description->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + _description->setInstantReplaces(Core::App().settings().instantReplacesValue()); _description->setSubmitSettings( Core::App().settings().sendSubmitWay()); diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 4d8ba97a2..a34288451 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -163,9 +163,7 @@ void InitField( not_null container, not_null field, not_null session) { - field->setInstantReplaces(Ui::InstantReplaces::Default()); - field->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + field->setInstantReplaces(Core::App().settings().instantReplacesValue()); auto options = Ui::Emoji::SuggestionsController::Options(); options.suggestExactFirstWord = false; Ui::Emoji::SuggestionsController::Init( @@ -846,9 +844,7 @@ not_null CreatePollBox::setupSolution( st::createPollFieldPadding); InitField(getDelegate()->outerContainer(), solution, session); solution->setMaxLength(kSolutionLimit + kErrorLimit); - solution->setInstantReplaces(Ui::InstantReplaces::Default()); - solution->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + solution->setInstantReplaces(Core::App().settings().instantReplacesValue()); solution->setMarkdownReplacesEnabled(rpl::single(true)); solution->setEditLinkCallback( DefaultEditLinkCallback(_controller, solution)); diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index e5a438b9d..015f1606f 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -242,9 +242,7 @@ void EditCaptionBox::setupField() { _controller->session().serverConfig().captionLengthMax); _field->setSubmitSettings( Core::App().settings().sendSubmitWay()); - _field->setInstantReplaces(Ui::InstantReplaces::Default()); - _field->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + _field->setInstantReplaces(Core::App().settings().instantReplacesValue()); _field->setMarkdownReplacesEnabled(rpl::single(true)); _field->setEditLinkCallback( DefaultEditLinkCallback(_controller, _field)); diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp index 6586b0125..db84db4e3 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/filters/edit_filter_chats_list.h" #include "chat_helpers/emoji_suggestions_widget.h" #include "ui/layers/generic_box.h" +#include "ui/text/text_options.h" #include "ui/text/text_utilities.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" @@ -623,12 +624,10 @@ void EditFilterBox( tr::lng_filters_new_name(), filter.title()), st::markdownLinkFieldPadding); - name->setInstantReplaces(Ui::InstantReplaces::Default()); - name->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); if (!isLocal) { name->setMaxLength(kMaxFilterTitleLength); } + name->setInstantReplaces(Core::App().settings().instantReplacesValue()); Ui::Emoji::SuggestionsController::Init( box->getDelegate()->outerContainer(), name, diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index ad8a1f0be..83a0af2a8 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -485,9 +485,7 @@ object_ptr Controller::createTitleEdit() { _peer->name), st::editPeerTitleMargins); result->entity()->setMaxLength(Ui::EditPeer::kMaxGroupChannelTitle); - result->entity()->setInstantReplaces(Ui::InstantReplaces::Default()); - result->entity()->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + result->entity()->setInstantReplaces(Core::App().settings().instantReplacesValue()); Ui::Emoji::SuggestionsController::Init( _wrap->window(), result->entity(), @@ -519,9 +517,7 @@ object_ptr Controller::createDescriptionEdit() { _peer->about()), st::editPeerDescriptionMargins); result->entity()->setMaxLength(Ui::EditPeer::kMaxChannelDescription); - result->entity()->setInstantReplaces(Ui::InstantReplaces::Default()); - result->entity()->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + result->entity()->setInstantReplaces(Core::App().settings().instantReplacesValue()); result->entity()->setSubmitSettings(Core::App().settings().sendSubmitWay()); Ui::Emoji::SuggestionsController::Init( _wrap->window(), diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 2b4202777..1dd0331fb 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -707,9 +707,7 @@ void SendFilesBox::setupCaption() { } Unexpected("action in MimeData hook."); }); - _caption->setInstantReplaces(Ui::InstantReplaces::Default()); - _caption->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + _caption->setInstantReplaces(Core::App().settings().instantReplacesValue()); _caption->setMarkdownReplacesEnabled(rpl::single(true)); _caption->setEditLinkCallback( DefaultEditLinkCallback(_controller, _caption)); diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index c36e1a53a..1aa1c231b 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -264,9 +264,7 @@ void ShareBox::prepareCommentField() { submit({}); }); - field->setInstantReplaces(Ui::InstantReplaces::Default()); - field->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + field->setInstantReplaces(Core::App().settings().instantReplacesValue()); field->setMarkdownReplacesEnabled(rpl::single(true)); if (_descriptor.initEditLink) { _descriptor.initEditLink(field); diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index adf3f13d0..644200de6 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -142,9 +142,7 @@ void EditLinkBox::prepare() { tr::lng_formatting_link_text(), _startText), st::markdownLinkFieldPadding); - text->setInstantReplaces(Ui::InstantReplaces::Default()); - text->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + text->setInstantReplaces(Core::App().settings().instantReplacesValue()); Ui::Emoji::SuggestionsController::Init( getDelegate()->outerContainer(), text, @@ -306,9 +304,7 @@ void InitMessageField( field->setAdditionalMargin(style::ConvertScale(4) - 4); field->customTab(true); - field->setInstantReplaces(Ui::InstantReplaces::Default()); - field->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + field->setInstantReplaces(Core::App().settings().instantReplacesValue()); field->setMarkdownReplacesEnabled(rpl::single(true)); field->setEditLinkCallback(DefaultEditLinkCallback(controller, field)); } diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index f411bd4bf..89329b07f 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/core_settings_proxy.h" #include "window/themes/window_themes_embedded.h" +#include "ui/widgets/input_fields.h" #include "ui/chat/attach/attach_send_files_way.h" #include "platform/platform_notifications_manager.h" #include "base/flags.h" @@ -356,6 +357,9 @@ public: } void setReplaceEmoji(bool value) { _replaceEmoji = value; + setInstantReplaces(value + ? Ui::InstantReplaces::Default() + : Ui::InstantReplaces::Custom()); } [[nodiscard]] bool replaceEmoji() const { return _replaceEmoji.current(); @@ -366,6 +370,34 @@ public: [[nodiscard]] rpl::producer replaceEmojiChanges() const { return _replaceEmoji.changes(); } + void setInstantReplaces(Ui::InstantReplaces replaces) { + _instantReplaces = replaces; + _instantReplacesSet = true; + } + [[nodiscard]] Ui::InstantReplaces instantReplaces() { + if (!_instantReplacesSet) { + setInstantReplaces(replaceEmoji() + ? Ui::InstantReplaces::Default() + : Ui::InstantReplaces::Custom()); + } + return _instantReplaces.current(); + } + [[nodiscard]] rpl::producer instantReplacesValue() { + if (!_instantReplacesSet) { + setInstantReplaces(replaceEmoji() + ? Ui::InstantReplaces::Default() + : Ui::InstantReplaces::Custom()); + } + return _instantReplaces.value(); + } + [[nodiscard]] rpl::producer instantReplacesChanges() { + if (!_instantReplacesSet) { + setInstantReplaces(replaceEmoji() + ? Ui::InstantReplaces::Default() + : Ui::InstantReplaces::Custom()); + } + return _instantReplaces.changes(); + } [[nodiscard]] bool suggestEmoji() const { return _suggestEmoji; } @@ -739,6 +771,8 @@ private: bool _loopAnimatedStickers = true; rpl::variable _largeEmoji = true; rpl::variable _replaceEmoji = true; + rpl::variable _instantReplaces; + bool _instantReplacesSet = false; bool _suggestEmoji = true; bool _suggestStickersByEmoji = true; rpl::variable _spellcheckerEnabled = true; diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index 065333bf1..195e4af5f 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -363,9 +363,7 @@ void SetupBio( save(); }); QObject::connect(bio, &Ui::InputField::changed, updated); - bio->setInstantReplaces(Ui::InstantReplaces::Default()); - bio->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + bio->setInstantReplaces(Core::App().settings().instantReplacesValue()); Ui::Emoji::SuggestionsController::Init( container->window(), bio, diff --git a/Telegram/SourceFiles/support/support_helper.cpp b/Telegram/SourceFiles/support/support_helper.cpp index ca112783e..5da93b8ec 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -83,9 +83,7 @@ EditInfoBox::EditInfoBox( _field->setMaxLength(kMaxSupportInfoLength); _field->setSubmitSettings( Core::App().settings().sendSubmitWay()); - _field->setInstantReplaces(Ui::InstantReplaces::Default()); - _field->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + _field->setInstantReplaces(Core::App().settings().instantReplacesValue()); _field->setMarkdownReplacesEnabled(rpl::single(true)); _field->setEditLinkCallback(DefaultEditLinkCallback(controller, _field)); } diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 253f3cdc2..2de9eda4b 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -971,9 +971,7 @@ void Notification::showReplyField() { _replyArea->setFocus(); _replyArea->setMaxLength(MaxMessageSize); _replyArea->setSubmitSettings(Ui::InputField::SubmitSettings::Both); - _replyArea->setInstantReplaces(Ui::InstantReplaces::Default()); - _replyArea->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + _replyArea->setInstantReplaces(Core::App().settings().instantReplacesValue()); _replyArea->setMarkdownReplacesEnabled(rpl::single(true)); // Catch mouse press event to activate the window.