1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51:01 +00:00

refactor(js): improve item navigation logic in goToListItem function

This commit is contained in:
Frédéric Guillot 2025-08-02 16:09:05 -07:00
parent 52c1386450
commit 2e28bf78bd

View file

@ -274,32 +274,45 @@ function goToListItem(offset) {
return; return;
} }
if (document.querySelector(".current-item") === null) { const currentItem = document.querySelector(".current-item");
// If no current item exists, select the first item
if (!currentItem) {
items[0].classList.add("current-item"); items[0].classList.add("current-item");
items[0].focus(); items[0].focus();
scrollPageTo(items[0]);
return; return;
} }
for (let i = 0; i < items.length; i++) { // Find the index of the current item
if (items[i].classList.contains("current-item")) { const currentIndex = items.indexOf(currentItem);
items[i].classList.remove("current-item"); if (currentIndex === -1) {
// Current item not found in visible items, select first item
currentItem.classList.remove("current-item");
items[0].classList.add("current-item");
items[0].focus();
scrollPageTo(items[0]);
return;
}
// By default adjust selection to the next item // Calculate the new item index
let itemOffset = (i + offset + items.length) % items.length; let newIndex;
// Allow jumping to top or bottom if (offset === TOP) {
if (offset === TOP) { newIndex = 0;
itemOffset = 0; } else if (offset === BOTTOM) {
} else if (offset === BOTTOM) { newIndex = items.length - 1;
itemOffset = items.length - 1; } else {
} newIndex = (currentIndex + offset + items.length) % items.length;
const item = items[itemOffset]; }
item.classList.add("current-item"); // Update selection if moving to a different item
scrollPageTo(item); if (newIndex !== currentIndex) {
item.focus(); const newItem = items[newIndex];
break; currentItem.classList.remove("current-item");
} newItem.classList.add("current-item");
newItem.focus();
scrollPageTo(newItem);
} }
} }
@ -593,12 +606,7 @@ function updateEntriesStatus(entryIDs, status, callback) {
if (callback) { if (callback) {
callback(resp); callback(resp);
} }
updateUnreadCounterValue(status === "read" ? -count : count);
if (status === "read") {
updateUnreadCounterValue(-count);
} else {
updateUnreadCounterValue(count);
}
}); });
}); });
} }