Support animated emoji in caption edit fields.

This commit is contained in:
John Preston 2022-07-01 17:01:39 +04:00
parent 00d1828fbe
commit 806c5ddf29
8 changed files with 60 additions and 64 deletions

View file

@ -241,20 +241,19 @@ void EditCaptionBox::rebuildPreview() {
}
void EditCaptionBox::setupField() {
const auto show = std::make_shared<Window::Show>(_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);

View file

@ -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<Window::Show>(_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();

View file

@ -286,12 +286,12 @@ Fn<bool(
};
}
void InitMessageField(
void InitMessageFieldHandlers(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field) {
field->setMinHeight(
st::historySendSize.height() - 2 * st::historySendPadding);
field->setMaxHeight(st::historyComposeFieldMaxHeight);
not_null<Ui::InputField*> field,
Window::GifPauseReason pauseReasonLevel) {
const auto show = std::make_shared<Window::Show>(controller);
const auto session = &controller->session();
field->setTagMimeProcessor(FieldTagMimeProcessor(controller));
field->setCustomEmojiFactory([=](QStringView data, Fn<void()> 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<Window::Show>(controller),
&controller->session(),
field));
DefaultEditLinkCallback(show, session, field));
InitSpellchecker(
std::make_shared<Window::Show>(controller),
session,
field);
}
void InitMessageFieldGeometry(not_null<Ui::InputField*> 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<Window::SessionController*> controller,
not_null<Ui::InputField*> 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<Window::SessionController*> controller,
not_null<Ui::InputField*> field) {
InitSpellchecker(
std::make_shared<Window::Show>(controller),
&controller->session(),
field);
}
bool HasSendText(not_null<const Ui::InputField*> field) {
const auto &text = field->getTextWithTags().text;
for (const auto &ch : text) {

View file

@ -24,6 +24,7 @@ class Session;
namespace Window {
class SessionController;
enum class GifPauseReason;
} // namespace Window
namespace Ui {
@ -43,6 +44,10 @@ Fn<bool(
not_null<Main::Session*> session,
not_null<Ui::InputField*> field,
const style::InputField *fieldStyle = nullptr);
void InitMessageFieldHandlers(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field,
Window::GifPauseReason pauseReasonLevel);
void InitMessageField(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field);
@ -52,9 +57,6 @@ void InitSpellchecker(
not_null<Main::Session*> session,
not_null<Ui::InputField*> field,
bool skipDictionariesManager = false);
void InitSpellchecker(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field);
bool HasSendText(not_null<const Ui::InputField*> field);

View file

@ -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 };
}

View file

@ -473,7 +473,6 @@ HistoryWidget::HistoryWidget(
}
Unexpected("action in MimeData hook.");
});
InitSpellchecker(controller, _field);
const auto suggestions = Ui::Emoji::SuggestionsController::Init(
this,

View file

@ -1426,7 +1426,6 @@ void ComposeControls::initField() {
_field,
&_window->session());
_raiseEmojiSuggestions = [=] { suggestions->raise(); };
InitSpellchecker(_window, _field);
const auto rawTextEdit = _field->rawTextEdit().get();
rpl::merge(

@ -1 +1 @@
Subproject commit 6bd7518109850d650a174b74e5582367555390da
Subproject commit 0b829240fd3ade757aa4e957c17d84a81ef1c3ff