Moved scroll keys from sections to compose controls.
This commit is contained in:
parent
4ad0837661
commit
b13e5ddce9
|
@ -721,6 +721,11 @@ rpl::producer<not_null<QKeyEvent*>> ComposeControls::keyEvents() const {
|
|||
});
|
||||
}
|
||||
|
||||
auto ComposeControls::scrollKeyEvents() const
|
||||
-> rpl::producer<not_null<QKeyEvent*>> {
|
||||
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<QEvent*> event) {
|
||||
return (event->type() == QEvent::KeyPress);
|
||||
}) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
||||
auto keyEvent = static_cast<QKeyEvent*>(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();
|
||||
|
|
|
@ -122,6 +122,8 @@ public:
|
|||
[[nodiscard]] rpl::producer<InlineChosen> inlineResultChosen() const;
|
||||
[[nodiscard]] rpl::producer<SendActionUpdate> sendActionUpdates() const;
|
||||
[[nodiscard]] rpl::producer<not_null<QEvent*>> viewportEvents() const;
|
||||
[[nodiscard]] auto scrollKeyEvents() const
|
||||
-> rpl::producer<not_null<QKeyEvent*>>;
|
||||
|
||||
using MimeDataHook = Fn<bool(
|
||||
not_null<const QMimeData*> 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<InlineChosen> _inlineResultChosen;
|
||||
rpl::event_stream<SendActionUpdate> _sendActionUpdates;
|
||||
rpl::event_stream<QString> _sendCommandRequests;
|
||||
rpl::event_stream<not_null<QKeyEvent*>> _scrollKeyEvents;
|
||||
|
||||
TextUpdateEvents _textUpdateEvents = TextUpdateEvents()
|
||||
| TextUpdateEvent::SaveDraft
|
||||
|
|
|
@ -488,6 +488,11 @@ void RepliesWidget::setupComposeControls() {
|
|||
showAtPosition(pos);
|
||||
}, lifetime());
|
||||
|
||||
_composeControls->scrollKeyEvents(
|
||||
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
||||
_scroll->keyPressEvent(e);
|
||||
}, lifetime());
|
||||
|
||||
_composeControls->keyEvents(
|
||||
) | rpl::start_with_next([=](not_null<QKeyEvent*> 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());
|
||||
|
||||
|
|
|
@ -231,6 +231,11 @@ void ScheduledWidget::setupComposeControls() {
|
|||
showAtPosition(pos);
|
||||
}, lifetime());
|
||||
|
||||
_composeControls->scrollKeyEvents(
|
||||
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
||||
_scroll->keyPressEvent(e);
|
||||
}, lifetime());
|
||||
|
||||
_composeControls->keyEvents(
|
||||
) | rpl::start_with_next([=](not_null<QKeyEvent*> 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());
|
||||
|
||||
|
|
Loading…
Reference in New Issue