From 9583b496531b682fb90afda6c5c707f0dbd2f825 Mon Sep 17 00:00:00 2001 From: Brian <18603393+brian6932@users.noreply.github.com> Date: Sat, 18 Jun 2022 07:48:55 -0400 Subject: [PATCH] Added a `Scroll to top` keyboard shortcut for splits (#3802) Co-authored-by: pajlada --- CHANGELOG.md | 1 + src/controllers/hotkeys/ActionNames.hpp | 1 + src/controllers/hotkeys/HotkeyController.cpp | 3 +++ src/widgets/Scrollbar.cpp | 5 +++++ src/widgets/Scrollbar.hpp | 1 + src/widgets/splits/Split.cpp | 6 ++++++ 6 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57a320999..4c00a6d53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Major: Added multi-channel searching to search dialog via keyboard shortcut. [Ctrl+Shift+F by default] (#3694) - Minor: Added `is:first-msg` search option. (#3700) - Minor: Added quotation marks in the permitted/blocked Automod messages for clarity. (#3654) +- Minor: Added a `Scroll to top` keyboard shortcut for splits. (#3802) - Minor: Adjust large stream thumbnail to 16:9 (#3655) - Minor: Fixed being unable to load Twitch Usercards from the `/mentions` tab. (#3623) - Minor: Add information about the user's operating system in the About page. (#3663) diff --git a/src/controllers/hotkeys/ActionNames.hpp b/src/controllers/hotkeys/ActionNames.hpp index f326c24c8..aa335a16c 100644 --- a/src/controllers/hotkeys/ActionNames.hpp +++ b/src/controllers/hotkeys/ActionNames.hpp @@ -89,6 +89,7 @@ inline const std::map actionNames{ 1, }}, {"scrollToBottom", ActionDefinition{"Scroll to the bottom"}}, + {"scrollToTop", ActionDefinition{"Scroll to the top"}}, {"setChannelNotification", ActionDefinition{ "Set channel live notification", diff --git a/src/controllers/hotkeys/HotkeyController.cpp b/src/controllers/hotkeys/HotkeyController.cpp index 7557fa67a..757197f65 100644 --- a/src/controllers/hotkeys/HotkeyController.cpp +++ b/src/controllers/hotkeys/HotkeyController.cpp @@ -375,6 +375,9 @@ void HotkeyController::addDefaults(std::set &addedHotkeys) this->tryAddDefault(addedHotkeys, HotkeyCategory::Split, QKeySequence("Ctrl+End"), "scrollToBottom", std::vector(), "scroll to bottom"); + this->tryAddDefault(addedHotkeys, HotkeyCategory::Split, + QKeySequence("Ctrl+Home"), "scrollToTop", + std::vector(), "scroll to top"); this->tryAddDefault(addedHotkeys, HotkeyCategory::Split, QKeySequence("F10"), "debug", std::vector(), "open debug popup"); diff --git a/src/widgets/Scrollbar.cpp b/src/widgets/Scrollbar.cpp index 67e2176bc..e9c98f2a6 100644 --- a/src/widgets/Scrollbar.cpp +++ b/src/widgets/Scrollbar.cpp @@ -76,6 +76,11 @@ void Scrollbar::scrollToBottom(bool animate) this->setDesiredValue(this->maximum_ - this->getLargeChange(), animate); } +void Scrollbar::scrollToTop(bool animate) +{ + this->setDesiredValue(this->minimum_ - this->getLargeChange(), animate); +} + bool Scrollbar::isAtBottom() const { return this->atBottom_; diff --git a/src/widgets/Scrollbar.hpp b/src/widgets/Scrollbar.hpp index 140a79921..764972d66 100644 --- a/src/widgets/Scrollbar.hpp +++ b/src/widgets/Scrollbar.hpp @@ -30,6 +30,7 @@ public: void clearHighlights(); void scrollToBottom(bool animate = false); + void scrollToTop(bool animate = false); bool isAtBottom() const; void setMaximum(qreal value); diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index a805b822e..dcc9691aa 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -333,6 +333,12 @@ void Split::addShortcuts() getSettings()->enableSmoothScrollingNewMessages.getValue()); return ""; }}, + {"scrollToTop", + [this](std::vector) -> QString { + this->getChannelView().getScrollBar().scrollToTop( + getSettings()->enableSmoothScrollingNewMessages.getValue()); + return ""; + }}, {"scrollPage", [this](std::vector arguments) -> QString { if (arguments.size() == 0)