Skip to content

Commit

Permalink
feat(keyboards): add shortcuts for scrolling chat
Browse files Browse the repository at this point in the history
  • Loading branch information
pinbraerts committed Aug 21, 2024
1 parent 2c1788a commit e8054fa
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
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 },
{ 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

0 comments on commit e8054fa

Please sign in to comment.