[Improvement] Allow non-emoji auto-replaces with emoji replacements disabled

This commit is contained in:
Eric Kotato 2022-09-11 04:01:25 +03:00 committed by Eric Kotato
parent 20d29fcd6c
commit fb30456059
9 changed files with 47 additions and 34 deletions

View file

@ -561,9 +561,7 @@ void GroupInfoBox::prepare() {
: tr::lng_dlg_new_group_name)(), : tr::lng_dlg_new_group_name)(),
_initialTitle); _initialTitle);
_title->setMaxLength(Ui::EditPeer::kMaxGroupChannelTitle); _title->setMaxLength(Ui::EditPeer::kMaxGroupChannelTitle);
_title->setInstantReplaces(Ui::InstantReplaces::Default()); _title->setInstantReplaces(Core::App().settings().instantReplacesValue());
_title->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
Ui::Emoji::SuggestionsController::Init( Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(), getDelegate()->outerContainer(),
_title, _title,
@ -577,9 +575,7 @@ void GroupInfoBox::prepare() {
tr::lng_create_group_description()); tr::lng_create_group_description());
_description->show(); _description->show();
_description->setMaxLength(Ui::EditPeer::kMaxChannelDescription); _description->setMaxLength(Ui::EditPeer::kMaxChannelDescription);
_description->setInstantReplaces(Ui::InstantReplaces::Default()); _description->setInstantReplaces(Core::App().settings().instantReplacesValue());
_description->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
_description->setSubmitSettings( _description->setSubmitSettings(
Core::App().settings().sendSubmitWay()); Core::App().settings().sendSubmitWay());

View file

@ -266,9 +266,7 @@ void InitField(
not_null<QWidget*> container, not_null<QWidget*> container,
not_null<Ui::InputField*> field, not_null<Ui::InputField*> field,
not_null<Main::Session*> session) { not_null<Main::Session*> session) {
field->setInstantReplaces(Ui::InstantReplaces::Default()); field->setInstantReplaces(Core::App().settings().instantReplacesValue());
field->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
auto options = Ui::Emoji::SuggestionsController::Options(); auto options = Ui::Emoji::SuggestionsController::Options();
options.suggestExactFirstWord = false; options.suggestExactFirstWord = false;
Ui::Emoji::SuggestionsController::Init( Ui::Emoji::SuggestionsController::Init(
@ -1041,9 +1039,7 @@ not_null<Ui::InputField*> CreatePollBox::setupSolution(
st::createPollFieldPadding); st::createPollFieldPadding);
InitField(getDelegate()->outerContainer(), solution, session); InitField(getDelegate()->outerContainer(), solution, session);
solution->setMaxLength(kSolutionLimit + kErrorLimit); solution->setMaxLength(kSolutionLimit + kErrorLimit);
solution->setInstantReplaces(Ui::InstantReplaces::Default()); solution->setInstantReplaces(Core::App().settings().instantReplacesValue());
solution->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
solution->setMarkdownReplacesEnabled(rpl::single(true)); solution->setMarkdownReplacesEnabled(rpl::single(true));
solution->setEditLinkCallback( solution->setEditLinkCallback(
DefaultEditLinkCallback(_controller->uiShow(), solution)); DefaultEditLinkCallback(_controller->uiShow(), solution));

View file

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/premium_limits_box.h" #include "boxes/premium_limits_box.h"
#include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/emoji_suggestions_widget.h"
#include "ui/layers/generic_box.h" #include "ui/layers/generic_box.h"
#include "ui/text/text_options.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/text/text_options.h" #include "ui/text/text_options.h"
#include "ui/widgets/checkbox.h" #include "ui/widgets/checkbox.h"
@ -413,12 +414,10 @@ void EditFilterBox(
tr::lng_filters_new_name(), tr::lng_filters_new_name(),
filter.title()), filter.title()),
st::markdownLinkFieldPadding); st::markdownLinkFieldPadding);
name->setInstantReplaces(Ui::InstantReplaces::Default());
name->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
if (!isLocal) { if (!isLocal) {
name->setMaxLength(kMaxFilterTitleLength); name->setMaxLength(kMaxFilterTitleLength);
} }
name->setInstantReplaces(Core::App().settings().instantReplacesValue());
Ui::Emoji::SuggestionsController::Init( Ui::Emoji::SuggestionsController::Init(
box->getDelegate()->outerContainer(), box->getDelegate()->outerContainer(),
name, name,

View file

@ -552,9 +552,7 @@ object_ptr<Ui::RpWidget> Controller::createTitleEdit() {
_peer->name()), _peer->name()),
st::editPeerTitleMargins); st::editPeerTitleMargins);
result->entity()->setMaxLength(Ui::EditPeer::kMaxGroupChannelTitle); result->entity()->setMaxLength(Ui::EditPeer::kMaxGroupChannelTitle);
result->entity()->setInstantReplaces(Ui::InstantReplaces::Default()); result->entity()->setInstantReplaces(Core::App().settings().instantReplacesValue());
result->entity()->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
Ui::Emoji::SuggestionsController::Init( Ui::Emoji::SuggestionsController::Init(
_wrap->window(), _wrap->window(),
result->entity(), result->entity(),
@ -656,9 +654,7 @@ object_ptr<Ui::RpWidget> Controller::createDescriptionEdit() {
_peer->about()), _peer->about()),
st::editPeerDescriptionMargins); st::editPeerDescriptionMargins);
result->entity()->setMaxLength(Ui::EditPeer::kMaxChannelDescription); result->entity()->setMaxLength(Ui::EditPeer::kMaxChannelDescription);
result->entity()->setInstantReplaces(Ui::InstantReplaces::Default()); result->entity()->setInstantReplaces(Core::App().settings().instantReplacesValue());
result->entity()->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
result->entity()->setSubmitSettings( result->entity()->setSubmitSettings(
Core::App().settings().sendSubmitWay()); Core::App().settings().sendSubmitWay());
Ui::Emoji::SuggestionsController::Init( Ui::Emoji::SuggestionsController::Init(

View file

@ -145,9 +145,7 @@ void EditLinkBox(
tr::lng_formatting_link_text(), tr::lng_formatting_link_text(),
startText), startText),
st::markdownLinkFieldPadding); st::markdownLinkFieldPadding);
text->setInstantReplaces(Ui::InstantReplaces::Default()); text->setInstantReplaces(Core::App().settings().instantReplacesValue());
text->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
Ui::Emoji::SuggestionsController::Init( Ui::Emoji::SuggestionsController::Init(
box->getDelegate()->outerContainer(), box->getDelegate()->outerContainer(),
text, text,
@ -349,9 +347,7 @@ void InitMessageFieldHandlers(
field->setCustomEmojiFactory( field->setCustomEmojiFactory(
session->data().customEmojiManager().factory(), session->data().customEmojiManager().factory(),
std::move(customEmojiPaused)); std::move(customEmojiPaused));
field->setInstantReplaces(Ui::InstantReplaces::Default()); field->setInstantReplaces(Core::App().settings().instantReplacesValue());
field->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
field->setMarkdownReplacesEnabled(rpl::single(true)); field->setMarkdownReplacesEnabled(rpl::single(true));
if (show) { if (show) {
field->setEditLinkCallback( field->setEditLinkCallback(

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/core_settings_proxy.h" #include "core/core_settings_proxy.h"
#include "media/media_common.h" #include "media/media_common.h"
#include "window/themes/window_themes_embedded.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 "ui/chat/attach/attach_send_files_way.h"
#include "base/flags.h" #include "base/flags.h"
#include "emoji.h" #include "emoji.h"
@ -431,6 +432,9 @@ public:
} }
void setReplaceEmoji(bool value) { void setReplaceEmoji(bool value) {
_replaceEmoji = value; _replaceEmoji = value;
setInstantReplaces(value
? Ui::InstantReplaces::Default()
: Ui::InstantReplaces::Custom());
} }
[[nodiscard]] bool replaceEmoji() const { [[nodiscard]] bool replaceEmoji() const {
return _replaceEmoji.current(); return _replaceEmoji.current();
@ -441,6 +445,34 @@ public:
[[nodiscard]] rpl::producer<bool> replaceEmojiChanges() const { [[nodiscard]] rpl::producer<bool> replaceEmojiChanges() const {
return _replaceEmoji.changes(); 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<Ui::InstantReplaces> instantReplacesValue() {
if (!_instantReplacesSet) {
setInstantReplaces(replaceEmoji()
? Ui::InstantReplaces::Default()
: Ui::InstantReplaces::Custom());
}
return _instantReplaces.value();
}
[[nodiscard]] rpl::producer<Ui::InstantReplaces> instantReplacesChanges() {
if (!_instantReplacesSet) {
setInstantReplaces(replaceEmoji()
? Ui::InstantReplaces::Default()
: Ui::InstantReplaces::Custom());
}
return _instantReplaces.changes();
}
[[nodiscard]] bool suggestEmoji() const { [[nodiscard]] bool suggestEmoji() const {
return _suggestEmoji; return _suggestEmoji;
} }
@ -952,6 +984,8 @@ private:
bool _loopAnimatedStickers = true; bool _loopAnimatedStickers = true;
rpl::variable<bool> _largeEmoji = true; rpl::variable<bool> _largeEmoji = true;
rpl::variable<bool> _replaceEmoji = true; rpl::variable<bool> _replaceEmoji = true;
rpl::variable<Ui::InstantReplaces> _instantReplaces;
bool _instantReplacesSet = false;
bool _suggestEmoji = true; bool _suggestEmoji = true;
bool _suggestStickersByEmoji = true; bool _suggestStickersByEmoji = true;
bool _suggestAnimatedEmoji = true; bool _suggestAnimatedEmoji = true;

View file

@ -15,7 +15,7 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL
#include "data/data_peer_id.h" #include "data/data_peer_id.h"
#include "base/parse_helper.h" #include "base/parse_helper.h"
#include "base/timer.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 "data/data_chat_filters.h"
#include "platform/platform_file_utilities.h" #include "platform/platform_file_utilities.h"

View file

@ -629,9 +629,7 @@ void SetupBio(
bio->setTextCursor(cursor); bio->setTextCursor(cursor);
bio->submits() | rpl::start_with_next([=] { save(); }, bio->lifetime()); bio->submits() | rpl::start_with_next([=] { save(); }, bio->lifetime());
bio->changes() | rpl::start_with_next(updated, bio->lifetime()); bio->changes() | rpl::start_with_next(updated, bio->lifetime());
bio->setInstantReplaces(Ui::InstantReplaces::Default()); bio->setInstantReplaces(Core::App().settings().instantReplacesValue());
bio->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
Ui::Emoji::SuggestionsController::Init( Ui::Emoji::SuggestionsController::Init(
container->window(), container->window(),
bio, bio,

View file

@ -85,9 +85,7 @@ EditInfoBox::EditInfoBox(
_field->setMaxLength(kMaxSupportInfoLength); _field->setMaxLength(kMaxSupportInfoLength);
_field->setSubmitSettings( _field->setSubmitSettings(
Core::App().settings().sendSubmitWay()); Core::App().settings().sendSubmitWay());
_field->setInstantReplaces(Ui::InstantReplaces::Default()); _field->setInstantReplaces(Core::App().settings().instantReplacesValue());
_field->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
_field->setMarkdownReplacesEnabled(rpl::single(true)); _field->setMarkdownReplacesEnabled(rpl::single(true));
_field->setEditLinkCallback( _field->setEditLinkCallback(
DefaultEditLinkCallback(controller->uiShow(), _field)); DefaultEditLinkCallback(controller->uiShow(), _field));