mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
Add keyboard shortcut to scroll current item to the top
This commit is contained in:
parent
84b83fc3c8
commit
cc8eb89ce0
18 changed files with 48 additions and 16 deletions
|
@ -475,6 +475,13 @@ function goToNextListItem() {
|
|||
}
|
||||
}
|
||||
|
||||
function scrollToCurrentItem() {
|
||||
let currentItem = document.querySelector(".current-item");
|
||||
if (currentItem !== null) {
|
||||
DomHelper.scrollPageTo(currentItem, true);
|
||||
}
|
||||
}
|
||||
|
||||
function decrementUnreadCounter(n) {
|
||||
updateUnreadCounterValue((current) => {
|
||||
return current - n;
|
||||
|
|
1
ui/static/js/bootstrap.js
vendored
1
ui/static/js/bootstrap.js
vendored
|
@ -17,6 +17,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
keyboardHandler.on("n", () => goToNext());
|
||||
keyboardHandler.on("h", () => goToPage("previous"));
|
||||
keyboardHandler.on("l", () => goToPage("next"));
|
||||
keyboardHandler.on("z t", () => scrollToCurrentItem());
|
||||
keyboardHandler.on("o", () => openSelectedItem());
|
||||
keyboardHandler.on("v", () => openOriginalLink());
|
||||
keyboardHandler.on("V", () => openOriginalLink(true));
|
||||
|
|
|
@ -10,13 +10,13 @@ class DomHelper {
|
|||
win.focus();
|
||||
}
|
||||
|
||||
static scrollPageTo(element) {
|
||||
static scrollPageTo(element, evenIfOnScreen) {
|
||||
let windowScrollPosition = window.pageYOffset;
|
||||
let windowHeight = document.documentElement.clientHeight;
|
||||
let viewportPosition = windowScrollPosition + windowHeight;
|
||||
let itemBottomPosition = element.offsetTop + element.offsetHeight;
|
||||
|
||||
if (viewportPosition - itemBottomPosition < 0 || viewportPosition - element.offsetTop > windowHeight) {
|
||||
if (evenIfOnScreen || viewportPosition - itemBottomPosition < 0 || viewportPosition - element.offsetTop > windowHeight) {
|
||||
window.scrollTo(0, element.offsetTop - 10);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue