From 70b82b7b597d0574466a668c2b801168ab0fcae0 Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 30 Aug 2019 13:40:56 -0400 Subject: [PATCH] Add scroll to top/bottom keybinds --- src/python/config_files.py | 4 ++++ src/qml/Shortcuts.qml | 12 ++++++++++++ src/qml/utils.js | 26 ++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/python/config_files.py b/src/python/config_files.py index bbe82f54..7be9f277 100644 --- a/src/python/config_files.py +++ b/src/python/config_files.py @@ -115,6 +115,10 @@ class UISettings(JSONConfigFile): "scrollDown": ["Alt+Down", "Alt+J"], "scrollPageUp": ["Alt+Ctrl+Up", "Alt+Ctrl+K", "PageUp"], "scrollPageDown": ["Alt+Ctrl+Down", "Alt+Ctrl+J", "PageDown"], + "scrollToTop": + ["Alt+Ctrl+Shift+Up", "Alt+Ctrl+Shift+K", "Home"], + "scrollToBottom": + ["Alt+Ctrl+Shift+Down", "Alt+Ctrl+Shift+J", "End"], "focusSidePane": ["Alt+S", "Ctrl+S"], "clearRoomFilter": ["Alt+Shift+S", "Ctrl+Shift+S"], diff --git a/src/qml/Shortcuts.qml b/src/qml/Shortcuts.qml index 08e6cc7d..d39fab79 100644 --- a/src/qml/Shortcuts.qml +++ b/src/qml/Shortcuts.qml @@ -48,6 +48,18 @@ HShortcutHandler { onHeld: pressed(event) } + HShortcut { + sequences: settings.keys.scrollToTop + onPressed: Utils.flickToTop(flickTarget) + onHeld: pressed(event) + } + + HShortcut { + sequences: settings.keys.scrollToBottom + onPressed: Utils.flickToBottom(flickTarget) + onHeld: pressed(event) + } + // SidePane diff --git a/src/qml/utils.js b/src/qml/utils.js index 897c2235..27afddfd 100644 --- a/src/qml/utils.js +++ b/src/qml/utils.js @@ -169,13 +169,31 @@ function getItem(array, mainKey, value) { } -function smartVerticalFlick(flickTarget, baseVelocity, fastMultiply=3) { - if (! flickTarget.interactive) { return } +function smartVerticalFlick(flickable, baseVelocity, fastMultiply=3) { + if (! flickable.interactive) { return } baseVelocity = -baseVelocity - let vel = -flickTarget.verticalVelocity + let vel = -flickable.verticalVelocity let fast = (baseVelocity < 0 && vel < baseVelocity / 2) || (baseVelocity > 0 && vel > baseVelocity / 2) - flickTarget.flick(0, baseVelocity * (fast ? fastMultiply : 1)) + flickable.flick(0, baseVelocity * (fast ? fastMultiply : 1)) +} + +function flickToTop(flickable) { + if (! flickable.interactive) return + if (flickable.visibleArea.yPosition < 0) return + + flickable.contentY -= flickable.contentHeight + flickable.returnToBounds() + flickable.flick(0, -100) // Force the delegates to load +} + +function flickToBottom(flickable) { + if (! flickable.interactive) return + if (flickable.visibleArea.yPosition < 0) return + + flickable.contentY = flickTarget.contentHeight - flickTarget.height + flickable.returnToBounds() + flickable.flick(0, 100) }