Skip to content

Commit e8054fa

Browse files
committed
feat(keyboards): add shortcuts for scrolling chat
1 parent 2c1788a commit e8054fa

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

Telegram/SourceFiles/core/shortcuts.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ const auto AutoRepeatCommands = base::flat_set<Command>{
3636
Command::ChatNext,
3737
Command::ChatFirst,
3838
Command::ChatLast,
39+
Command::ChatScrollDown,
40+
Command::ChatScrollUp,
41+
Command::ChatScrollScreenDown,
42+
Command::ChatScrollScreenUp,
43+
Command::ChatScrollHalfScreenDown,
44+
Command::ChatScrollHalfScreenUp,
3945
};
4046

4147
const auto MediaCommands = base::flat_set<Command>{
@@ -73,6 +79,14 @@ const auto CommandByName = base::flat_map<QString, Command>{
7379
{ u"previous_chat"_q , Command::ChatPrevious },
7480
{ u"next_chat"_q , Command::ChatNext },
7581
{ u"first_chat"_q , Command::ChatFirst },
82+
{ u"chat_scroll_down"_q , Command::ChatScrollDown },
83+
{ u"chat_scroll_up"_q , Command::ChatScrollUp },
84+
{ u"chat_scroll_screen_down"_q, Command::ChatScrollScreenDown },
85+
{ u"chat_scroll_screen_up"_q , Command::ChatScrollScreenUp },
86+
{ u"chat_scroll_half_screen_down"_q, Command::ChatScrollHalfScreenDown },
87+
{ u"chat_scroll_half_screen_up"_q , Command::ChatScrollHalfScreenUp },
88+
{ u"chat_scroll_top"_q , Command::ChatScrollTop },
89+
{ u"chat_scroll_bottom"_q, Command::ChatScrollBottom },
7690
{ u"last_chat"_q , Command::ChatLast },
7791
{ u"self_chat"_q , Command::ChatSelf },
7892

@@ -130,6 +144,14 @@ const auto CommandNames = base::flat_map<Command, QString>{
130144
{ Command::ChatFirst , u"first_chat"_q },
131145
{ Command::ChatLast , u"last_chat"_q },
132146
{ Command::ChatSelf , u"self_chat"_q },
147+
{ Command::ChatScrollDown , u"chat_scroll_down"_q },
148+
{ Command::ChatScrollUp , u"chat_scroll_up"_q },
149+
{ Command::ChatScrollScreenDown, u"chat_scroll_screen_down"_q },
150+
{ Command::ChatScrollScreenUp , u"chat_scroll_screen_up"_q },
151+
{ Command::ChatScrollHalfScreenDown, u"chat_scroll_half_screen_down"_q },
152+
{ Command::ChatScrollHalfScreenUp , u"chat_scroll_half_screen_up"_q },
153+
{ Command::ChatScrollTop , u"chat_scroll_top"_q },
154+
{ Command::ChatScrollBottom, u"chat_scroll_bottom"_q },
133155

134156
{ Command::FolderPrevious , u"previous_folder"_q },
135157
{ Command::FolderNext , u"next_folder"_q },
@@ -396,6 +418,9 @@ void Manager::fillDefaults() {
396418
set(u"ctrl+pgup"_q, Command::ChatPrevious);
397419
set(u"alt+up"_q, Command::ChatPrevious);
398420

421+
set(u"pgup"_q, Command::ChatScrollScreenUp);
422+
set(u"pgdown"_q, Command::ChatScrollScreenDown);
423+
399424
set(u"%1+tab"_q.arg(ctrl), Command::ChatNext);
400425
set(u"%1+shift+tab"_q.arg(ctrl), Command::ChatPrevious);
401426
set(u"%1+backtab"_q.arg(ctrl), Command::ChatPrevious);

Telegram/SourceFiles/core/shortcuts.h

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ enum class Command {
2222
MediaPrevious,
2323
MediaNext,
2424

25+
ChatScrollDown,
26+
ChatScrollUp,
27+
ChatScrollScreenDown,
28+
ChatScrollScreenUp,
29+
ChatScrollHalfScreenDown,
30+
ChatScrollHalfScreenUp,
31+
ChatScrollTop,
32+
ChatScrollBottom,
33+
2534
Search,
2635

2736
ChatPrevious,

Telegram/SourceFiles/history/history_widget.cpp

+24-4
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,30 @@ void HistoryWidget::setupShortcuts() {
19631963
controller()->searchInChat(_history);
19641964
return true;
19651965
});
1966+
request->check(Command::ChatScrollUp) && request->handle([=] {
1967+
return touchScroll({ 0, _scroll->height() / 10 });
1968+
});
1969+
request->check(Command::ChatScrollDown) && request->handle([=] {
1970+
return touchScroll({ 0, -_scroll->height() / 10 });
1971+
});
1972+
request->check(Command::ChatScrollScreenUp) && request->handle([=] {
1973+
return touchScroll({ 0, _scroll->height() });
1974+
});
1975+
request->check(Command::ChatScrollScreenDown) && request->handle([=] {
1976+
return touchScroll({ 0, -_scroll->height() });
1977+
});
1978+
request->check(Command::ChatScrollHalfScreenUp) && request->handle([=] {
1979+
return touchScroll({ 0, _scroll->height() / 2 });
1980+
});
1981+
request->check(Command::ChatScrollHalfScreenDown) && request->handle([=] {
1982+
return touchScroll({ 0, -_scroll->height() / 2 });
1983+
});
1984+
request->check(Command::ChatScrollTop) && request->handle([=] {
1985+
return touchScroll({ 0, _scroll->scrollTopMax() });
1986+
});
1987+
request->check(Command::ChatScrollBottom) && request->handle([=] {
1988+
return touchScroll({ 0, -_scroll->scrollTopMax() });
1989+
});
19661990
_canSendMessages
19671991
&& request->check(Command::ShowScheduled, 1)
19681992
&& request->handle([=] {
@@ -6742,10 +6766,6 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) {
67426766
}
67436767
} else if (e->key() == Qt::Key_Back) {
67446768
_cancelRequests.fire({});
6745-
} else if (e->key() == Qt::Key_PageDown) {
6746-
_scroll->keyPressEvent(e);
6747-
} else if (e->key() == Qt::Key_PageUp) {
6748-
_scroll->keyPressEvent(e);
67496769
} else if (e->key() == Qt::Key_Down && !commonModifiers) {
67506770
_scroll->keyPressEvent(e);
67516771
} else if (e->key() == Qt::Key_Up && !commonModifiers) {

0 commit comments

Comments
 (0)