Skip to content

feat(keyboards): add shortcuts for scrolling chat #28294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Telegram/SourceFiles/core/shortcuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const auto AutoRepeatCommands = base::flat_set<Command>{
Command::ChatNext,
Command::ChatFirst,
Command::ChatLast,
Command::ChatScrollDown,
Command::ChatScrollUp,
Command::ChatScrollScreenDown,
Command::ChatScrollScreenUp,
Command::ChatScrollHalfScreenDown,
Command::ChatScrollHalfScreenUp,
};

const auto MediaCommands = base::flat_set<Command>{
Expand Down Expand Up @@ -73,6 +79,14 @@ const auto CommandByName = base::flat_map<QString, Command>{
{ u"previous_chat"_q , Command::ChatPrevious },
{ u"next_chat"_q , Command::ChatNext },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is well to do.

{ u"first_chat"_q , Command::ChatFirst },
{ u"chat_scroll_down"_q , Command::ChatScrollDown },
{ u"chat_scroll_up"_q , Command::ChatScrollUp },
{ u"chat_scroll_screen_down"_q, Command::ChatScrollScreenDown },
{ u"chat_scroll_screen_up"_q , Command::ChatScrollScreenUp },
{ u"chat_scroll_half_screen_down"_q, Command::ChatScrollHalfScreenDown },
{ u"chat_scroll_half_screen_up"_q , Command::ChatScrollHalfScreenUp },
{ u"chat_scroll_top"_q , Command::ChatScrollTop },
{ u"chat_scroll_bottom"_q, Command::ChatScrollBottom },
{ u"last_chat"_q , Command::ChatLast },
{ u"self_chat"_q , Command::ChatSelf },

Expand Down Expand Up @@ -130,6 +144,14 @@ const auto CommandNames = base::flat_map<Command, QString>{
{ Command::ChatFirst , u"first_chat"_q },
{ Command::ChatLast , u"last_chat"_q },
{ Command::ChatSelf , u"self_chat"_q },
{ Command::ChatScrollDown , u"chat_scroll_down"_q },
{ Command::ChatScrollUp , u"chat_scroll_up"_q },
{ Command::ChatScrollScreenDown, u"chat_scroll_screen_down"_q },
{ Command::ChatScrollScreenUp , u"chat_scroll_screen_up"_q },
{ Command::ChatScrollHalfScreenDown, u"chat_scroll_half_screen_down"_q },
{ Command::ChatScrollHalfScreenUp , u"chat_scroll_half_screen_up"_q },
{ Command::ChatScrollTop , u"chat_scroll_top"_q },
{ Command::ChatScrollBottom, u"chat_scroll_bottom"_q },

{ Command::FolderPrevious , u"previous_folder"_q },
{ Command::FolderNext , u"next_folder"_q },
Expand Down Expand Up @@ -396,6 +418,9 @@ void Manager::fillDefaults() {
set(u"ctrl+pgup"_q, Command::ChatPrevious);
set(u"alt+up"_q, Command::ChatPrevious);

set(u"pgup"_q, Command::ChatScrollScreenUp);
set(u"pgdown"_q, Command::ChatScrollScreenDown);

set(u"%1+tab"_q.arg(ctrl), Command::ChatNext);
set(u"%1+shift+tab"_q.arg(ctrl), Command::ChatPrevious);
set(u"%1+backtab"_q.arg(ctrl), Command::ChatPrevious);
Expand Down
9 changes: 9 additions & 0 deletions Telegram/SourceFiles/core/shortcuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ enum class Command {
MediaPrevious,
MediaNext,

ChatScrollDown,
ChatScrollUp,
ChatScrollScreenDown,
ChatScrollScreenUp,
ChatScrollHalfScreenDown,
ChatScrollHalfScreenUp,
ChatScrollTop,
ChatScrollBottom,

Search,

ChatPrevious,
Expand Down
28 changes: 24 additions & 4 deletions Telegram/SourceFiles/history/history_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,30 @@ void HistoryWidget::setupShortcuts() {
controller()->searchInChat(_history);
return true;
});
request->check(Command::ChatScrollUp) && request->handle([=] {
return touchScroll({ 0, _scroll->height() / 10 });
});
request->check(Command::ChatScrollDown) && request->handle([=] {
return touchScroll({ 0, -_scroll->height() / 10 });
});
request->check(Command::ChatScrollScreenUp) && request->handle([=] {
return touchScroll({ 0, _scroll->height() });
});
request->check(Command::ChatScrollScreenDown) && request->handle([=] {
return touchScroll({ 0, -_scroll->height() });
});
request->check(Command::ChatScrollHalfScreenUp) && request->handle([=] {
return touchScroll({ 0, _scroll->height() / 2 });
});
request->check(Command::ChatScrollHalfScreenDown) && request->handle([=] {
return touchScroll({ 0, -_scroll->height() / 2 });
});
request->check(Command::ChatScrollTop) && request->handle([=] {
return touchScroll({ 0, _scroll->scrollTopMax() });
});
request->check(Command::ChatScrollBottom) && request->handle([=] {
return touchScroll({ 0, -_scroll->scrollTopMax() });
});
_canSendMessages
&& request->check(Command::ShowScheduled, 1)
&& request->handle([=] {
Expand Down Expand Up @@ -6742,10 +6766,6 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) {
}
} else if (e->key() == Qt::Key_Back) {
_cancelRequests.fire({});
} else if (e->key() == Qt::Key_PageDown) {
_scroll->keyPressEvent(e);
} else if (e->key() == Qt::Key_PageUp) {
_scroll->keyPressEvent(e);
} else if (e->key() == Qt::Key_Down && !commonModifiers) {
_scroll->keyPressEvent(e);
} else if (e->key() == Qt::Key_Up && !commonModifiers) {
Expand Down