From fb30456059a1dedee6d48cc68da58302c5bffc7c 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 ++--- .../boxes/filters/edit_filter_box.cpp | 5 ++- .../boxes/peers/edit_peer_info_box.cpp | 8 ++--- .../chat_helpers/message_field.cpp | 8 ++--- Telegram/SourceFiles/core/core_settings.h | 34 +++++++++++++++++++ .../SourceFiles/kotato/kotato_settings.cpp | 2 +- .../settings/settings_information.cpp | 4 +-- .../SourceFiles/support/support_helper.cpp | 4 +-- 9 files changed, 47 insertions(+), 34 deletions(-) diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 6b9a0852c..eabcdb22a 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -561,9 +561,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, @@ -577,9 +575,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 1d02b5e52..c2901ae5f 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -266,9 +266,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( @@ -1041,9 +1039,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->uiShow(), solution)); diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp index 03eedb753..b060e7499 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/premium_limits_box.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/text/text_options.h" #include "ui/widgets/checkbox.h" @@ -413,12 +414,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 99427aca0..4c64d41bf 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -552,9 +552,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(), @@ -656,9 +654,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( diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 557d0c337..91a5267b2 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -145,9 +145,7 @@ void EditLinkBox( 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( box->getDelegate()->outerContainer(), text, @@ -349,9 +347,7 @@ void InitMessageFieldHandlers( field->setCustomEmojiFactory( session->data().customEmojiManager().factory(), std::move(customEmojiPaused)); - field->setInstantReplaces(Ui::InstantReplaces::Default()); - field->setInstantReplacesEnabled( - Core::App().settings().replaceEmojiValue()); + field->setInstantReplaces(Core::App().settings().instantReplacesValue()); field->setMarkdownReplacesEnabled(rpl::single(true)); if (show) { field->setEditLinkCallback( diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 2588923c6..48d63c5c2 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/core_settings_proxy.h" #include "media/media_common.h" #include "window/themes/window_themes_embedded.h" +#include "ui/widgets/fields/input_field.h" #include "ui/chat/attach/attach_send_files_way.h" #include "base/flags.h" #include "emoji.h" @@ -431,6 +432,9 @@ public: } void setReplaceEmoji(bool value) { _replaceEmoji = value; + setInstantReplaces(value + ? Ui::InstantReplaces::Default() + : Ui::InstantReplaces::Custom()); } [[nodiscard]] bool replaceEmoji() const { return _replaceEmoji.current(); @@ -441,6 +445,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; } @@ -952,6 +984,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; bool _suggestAnimatedEmoji = true; diff --git a/Telegram/SourceFiles/kotato/kotato_settings.cpp b/Telegram/SourceFiles/kotato/kotato_settings.cpp index 4df75d98c..9e3345cba 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings.cpp @@ -15,7 +15,7 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL #include "data/data_peer_id.h" #include "base/parse_helper.h" #include "base/timer.h" -#include "ui/widgets/input_fields.h" +#include "ui/widgets/fields/input_field.h" #include "data/data_chat_filters.h" #include "platform/platform_file_utilities.h" diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index 468d745fe..fc8b9052f 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -629,9 +629,7 @@ void SetupBio( bio->setTextCursor(cursor); bio->submits() | rpl::start_with_next([=] { save(); }, bio->lifetime()); bio->changes() | rpl::start_with_next(updated, bio->lifetime()); - 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 08f27db07..ffe490a74 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -85,9 +85,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->uiShow(), _field));