Make custom text replaces work without replace emoji being enabled (#242)

This commit is contained in:
blank X 2021-12-17 14:00:14 +00:00 committed by GitHub
parent ca8b92d1e1
commit a851f7711d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 49 additions and 45 deletions

View file

@ -503,9 +503,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,
@ -519,9 +517,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

@ -162,9 +162,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(
@ -842,9 +840,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, solution)); DefaultEditLinkCallback(_controller, solution));

View file

@ -242,9 +242,7 @@ void EditCaptionBox::setupField() {
_controller->session().serverConfig().captionLengthMax); _controller->session().serverConfig().captionLengthMax);
_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, _field)); DefaultEditLinkCallback(_controller, _field));

View file

@ -627,9 +627,7 @@ void EditFilterBox(
if (!isLocal) { if (!isLocal) {
name->setMaxLength(kMaxFilterTitleLength); name->setMaxLength(kMaxFilterTitleLength);
} }
name->setInstantReplaces(Ui::InstantReplaces::Default()); name->setInstantReplaces(Core::App().settings().instantReplacesValue());
name->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
Ui::Emoji::SuggestionsController::Init( Ui::Emoji::SuggestionsController::Init(
box->getDelegate()->outerContainer(), box->getDelegate()->outerContainer(),
name, name,

View file

@ -481,9 +481,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(),
@ -515,9 +513,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(Core::App().settings().sendSubmitWay()); result->entity()->setSubmitSettings(Core::App().settings().sendSubmitWay());
Ui::Emoji::SuggestionsController::Init( Ui::Emoji::SuggestionsController::Init(
_wrap->window(), _wrap->window(),

View file

@ -706,9 +706,7 @@ void SendFilesBox::setupCaption() {
} }
Unexpected("action in MimeData hook."); Unexpected("action in MimeData hook.");
}); });
_caption->setInstantReplaces(Ui::InstantReplaces::Default()); _caption->setInstantReplaces(Core::App().settings().instantReplacesValue());
_caption->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
_caption->setMarkdownReplacesEnabled(rpl::single(true)); _caption->setMarkdownReplacesEnabled(rpl::single(true));
_caption->setEditLinkCallback( _caption->setEditLinkCallback(
DefaultEditLinkCallback(_controller, _caption)); DefaultEditLinkCallback(_controller, _caption));

View file

@ -221,9 +221,7 @@ void ShareBox::prepareCommentField() {
submit({}); submit({});
}); });
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 (_descriptor.initEditLink) { if (_descriptor.initEditLink) {
_descriptor.initEditLink(field); _descriptor.initEditLink(field);

View file

@ -142,9 +142,7 @@ void EditLinkBox::prepare() {
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(
getDelegate()->outerContainer(), getDelegate()->outerContainer(),
text, text,
@ -306,9 +304,7 @@ void InitMessageField(
field->setAdditionalMargin(style::ConvertScale(4) - 4); field->setAdditionalMargin(style::ConvertScale(4) - 4);
field->customTab(true); field->customTab(true);
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(DefaultEditLinkCallback(controller, field)); field->setEditLinkCallback(DefaultEditLinkCallback(controller, field));
} }

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "core/core_settings_proxy.h" #include "core/core_settings_proxy.h"
#include "window/themes/window_themes_embedded.h" #include "window/themes/window_themes_embedded.h"
#include "ui/widgets/input_fields.h"
#include "ui/chat/attach/attach_send_files_way.h" #include "ui/chat/attach/attach_send_files_way.h"
#include "platform/platform_notifications_manager.h" #include "platform/platform_notifications_manager.h"
#include "base/flags.h" #include "base/flags.h"
@ -357,6 +358,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();
@ -367,6 +371,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;
} }
@ -727,6 +759,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;
rpl::variable<bool> _spellcheckerEnabled = true; rpl::variable<bool> _spellcheckerEnabled = true;

View file

@ -363,9 +363,7 @@ void SetupBio(
save(); save();
}); });
QObject::connect(bio, &Ui::InputField::changed, updated); QObject::connect(bio, &Ui::InputField::changed, updated);
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

@ -83,9 +83,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(DefaultEditLinkCallback(controller, _field)); _field->setEditLinkCallback(DefaultEditLinkCallback(controller, _field));
} }

View file

@ -949,9 +949,7 @@ void Notification::showReplyField() {
_replyArea->setFocus(); _replyArea->setFocus();
_replyArea->setMaxLength(MaxMessageSize); _replyArea->setMaxLength(MaxMessageSize);
_replyArea->setSubmitSettings(Ui::InputField::SubmitSettings::Both); _replyArea->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
_replyArea->setInstantReplaces(Ui::InstantReplaces::Default()); _replyArea->setInstantReplaces(Core::App().settings().instantReplacesValue());
_replyArea->setInstantReplacesEnabled(
Core::App().settings().replaceEmojiValue());
_replyArea->setMarkdownReplacesEnabled(rpl::single(true)); _replyArea->setMarkdownReplacesEnabled(rpl::single(true));
// Catch mouse press event to activate the window. // Catch mouse press event to activate the window.