diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 5acb563bfb..1fcead3648 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -721,6 +721,11 @@ rpl::producer> ComposeControls::keyEvents() const { }); } +auto ComposeControls::scrollKeyEvents() const +-> rpl::producer> { + return _scrollKeyEvents.events(); +} + auto ComposeControls::sendContentRequests(SendRequestType requestType) const { auto filter = rpl::filter([=] { const auto type = (_mode == Mode::Normal) @@ -947,6 +952,7 @@ void ComposeControls::init() { initSendButton(); initWriteRestriction(); initVoiceRecordBar(); + initKeyHandler(); _botCommandStart->setClickedCallback([=] { setText({ "/" }); }); @@ -1048,6 +1054,22 @@ void ComposeControls::drawRestrictedWrite(Painter &p, const QString &error) { style::al_center); } +void ComposeControls::initKeyHandler() { + _wrap->events( + ) | rpl::filter([=](not_null event) { + return (event->type() == QEvent::KeyPress); + }) | rpl::start_with_next([=](not_null e) { + auto keyEvent = static_cast(e.get()); + const auto key = keyEvent->key(); + if ((key == Qt::Key_Up) + || (key == Qt::Key_Down) + || (key == Qt::Key_PageUp) + || (key == Qt::Key_PageDown)) { + _scrollKeyEvents.fire(std::move(keyEvent)); + } + }, _wrap->lifetime()); +} + void ComposeControls::initField() { _field->setMaxHeight(st::historyComposeFieldMaxHeight); updateSubmitSettings(); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h index d6328a055b..2e04bb2901 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h @@ -122,6 +122,8 @@ public: [[nodiscard]] rpl::producer inlineResultChosen() const; [[nodiscard]] rpl::producer sendActionUpdates() const; [[nodiscard]] rpl::producer> viewportEvents() const; + [[nodiscard]] auto scrollKeyEvents() const + -> rpl::producer>; using MimeDataHook = Fn data, @@ -189,6 +191,7 @@ private: void initWriteRestriction(); void initVoiceRecordBar(); void initAutocomplete(); + void initKeyHandler(); void updateSubmitSettings(); void updateSendButtonType(); void updateHeight(); @@ -290,6 +293,7 @@ private: rpl::event_stream _inlineResultChosen; rpl::event_stream _sendActionUpdates; rpl::event_stream _sendCommandRequests; + rpl::event_stream> _scrollKeyEvents; TextUpdateEvents _textUpdateEvents = TextUpdateEvents() | TextUpdateEvent::SaveDraft diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 5b8ee8c4aa..25f9e2566f 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -488,6 +488,11 @@ void RepliesWidget::setupComposeControls() { showAtPosition(pos); }, lifetime()); + _composeControls->scrollKeyEvents( + ) | rpl::start_with_next([=](not_null e) { + _scroll->keyPressEvent(e); + }, lifetime()); + _composeControls->keyEvents( ) | rpl::start_with_next([=](not_null e) { if (e->key() == Qt::Key_Up) { @@ -501,15 +506,6 @@ void RepliesWidget::setupComposeControls() { _scroll->keyPressEvent(e); } e->accept(); - } else if (e->key() == Qt::Key_Down) { - _scroll->keyPressEvent(e); - e->accept(); - } else if (e->key() == Qt::Key_PageDown) { - _scroll->keyPressEvent(e); - e->accept(); - } else if (e->key() == Qt::Key_PageUp) { - _scroll->keyPressEvent(e); - e->accept(); } }, lifetime()); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 9faee54c7a..690315db98 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -231,6 +231,11 @@ void ScheduledWidget::setupComposeControls() { showAtPosition(pos); }, lifetime()); + _composeControls->scrollKeyEvents( + ) | rpl::start_with_next([=](not_null e) { + _scroll->keyPressEvent(e); + }, lifetime()); + _composeControls->keyEvents( ) | rpl::start_with_next([=](not_null e) { if (e->key() == Qt::Key_Up) { @@ -246,9 +251,6 @@ void ScheduledWidget::setupComposeControls() { _scroll->keyPressEvent(e); } e->accept(); - } else if (e->key() == Qt::Key_Down) { - _scroll->keyPressEvent(e); - e->accept(); } }, lifetime());