diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index bd089a9b5..8377ff531 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/premium_limits_box.h" #include "boxes/premium_preview_box.h" #include "chat_helpers/emoji_suggestions_widget.h" +#include "chat_helpers/field_autocomplete.h" #include "chat_helpers/message_field.h" #include "chat_helpers/tabbed_panel.h" #include "chat_helpers/tabbed_selector.h" @@ -371,6 +372,14 @@ void EditCaptionBox::StartPhotoEdit( }); } +void EditCaptionBox::showFinished() { + if (const auto raw = _autocomplete.get()) { + InvokeQueued(raw, [=] { + raw->raise(); + }); + } +} + void EditCaptionBox::prepare() { const auto button = addButton(tr::lng_settings_save(), [=] { save(); }); addButton(tr::lng_cancel(), [=] { closeBox(); }); @@ -525,6 +534,7 @@ void EditCaptionBox::setupField() { _field.get(), Window::GifPauseReason::Layer, allow); + setupFieldAutocomplete(); Ui::Emoji::SuggestionsController::Init( getDelegate()->outerContainer(), _field, @@ -562,6 +572,56 @@ void EditCaptionBox::setupField() { }); } +void EditCaptionBox::setupFieldAutocomplete() { + const auto parent = getDelegate()->outerContainer(); + ChatHelpers::InitFieldAutocomplete(_autocomplete, { + .parent = parent, + .show = _controller->uiShow(), + .field = _field.get(), + .peer = _historyItem->history()->peer, + .features = [=] { + auto result = ChatHelpers::ComposeFeatures(); + result.autocompleteCommands = false; + result.suggestStickersByEmoji = false; + return result; + }, + }); + const auto raw = _autocomplete.get(); + const auto scheduled = std::make_shared(); + const auto recountPostponed = [=] { + if (*scheduled) { + return; + } + *scheduled = true; + Ui::PostponeCall(raw, [=] { + *scheduled = false; + + auto full = parent->rect(); + auto field = Ui::MapFrom(parent, this, _field->geometry()); + _autocomplete->setBoundings(QRect( + field.x() - _field->x(), + st::defaultBox.margin.top(), + width(), + (field.y() + + st::defaultComposeFiles.caption.textMargins.top() + + st::defaultComposeFiles.caption.placeholderShift + + st::defaultComposeFiles.caption.placeholderFont->height + - st::defaultBox.margin.top()))); + }); + }; + for (auto w = (QWidget*)_field.get(); w; w = w->parentWidget()) { + base::install_event_filter(raw, w, [=](not_null e) { + if (e->type() == QEvent::Move || e->type() == QEvent::Resize) { + recountPostponed(); + } + return base::EventFilterResult::Continue; + }); + if (w == parent) { + break; + } + } +} + void EditCaptionBox::setInitialText() { _field->setTextWithTags( _initialText, diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.h b/Telegram/SourceFiles/boxes/edit_caption_box.h index af72a250f..745350616 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.h +++ b/Telegram/SourceFiles/boxes/edit_caption_box.h @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace ChatHelpers { class TabbedPanel; +class FieldAutocomplete; } // namespace ChatHelpers namespace Window { @@ -68,6 +69,8 @@ public: bool invertCaption, Fn saved); + void showFinished() override; + protected: void prepare() override; void setInnerFocus() override; @@ -81,6 +84,7 @@ private: void setupEditEventHandler(); void setupPhotoEditorEventHandler(); void setupField(); + void setupFieldAutocomplete(); void setupControls(); void setInitialText(); @@ -115,6 +119,8 @@ private: const base::unique_qptr _field; const base::unique_qptr _emojiToggle; + std::unique_ptr _autocomplete; + base::unique_qptr _content; base::unique_qptr _emojiPanel; base::unique_qptr _emojiFilter;