fix: small QoL: return to the last selected menu location (#1629)

## Summary

* **What is the goal of this PR?** Small UX improvement to the Home
screen by preserving the last selected cursor position when returning to
it.

It supersedes #985 and #1103, which are both significantly outdated and
hundreds of commits behind master.

---

### AI Usage

Did you use AI tools to help write this code? _**< YES >**_
This commit is contained in:
Uri Tauber
2026-05-19 08:41:39 -05:00
committed by GitHub
parent dac7fef49d
commit 08461c08e7
7 changed files with 77 additions and 29 deletions
+24 -21
View File
@@ -113,11 +113,12 @@ void HomeActivity::onEnter() {
hasOpdsServers = OPDS_STORE.hasServers();
selectorIndex = 0;
const auto& metrics = UITheme::getInstance().getMetrics();
loadRecentBooks(metrics.homeRecentBooksCount);
const auto base = static_cast<int>(recentBooks.size());
selectorIndex = initialMenuItem == HomeMenuItem::NONE ? 0 : base + menuItemToIndex(initialMenuItem, hasOpdsServers);
// Trigger first update
requestUpdate();
}
@@ -179,27 +180,29 @@ void HomeActivity::loop() {
});
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
// Calculate dynamic indices based on which options are available
int idx = 0;
int menuSelectedIndex = selectorIndex - static_cast<int>(recentBooks.size());
const int fileBrowserIdx = idx++;
const int recentsIdx = idx++;
const int opdsLibraryIdx = hasOpdsServers ? idx++ : -1;
const int fileTransferIdx = idx++;
const int settingsIdx = idx;
if (selectorIndex < recentBooks.size()) {
onSelectBook(recentBooks[selectorIndex].path);
} else if (menuSelectedIndex == fileBrowserIdx) {
onFileBrowserOpen();
} else if (menuSelectedIndex == recentsIdx) {
onRecentsOpen();
} else if (menuSelectedIndex == opdsLibraryIdx) {
onOpdsBrowserOpen();
} else if (menuSelectedIndex == fileTransferIdx) {
onFileTransferOpen();
} else if (menuSelectedIndex == settingsIdx) {
onSettingsOpen();
} else {
const int menuIndex = selectorIndex - static_cast<int>(recentBooks.size());
switch (indexToMenuItem(menuIndex, hasOpdsServers)) {
case HomeMenuItem::FILE_BROWSER:
onFileBrowserOpen();
break;
case HomeMenuItem::RECENTS:
onRecentsOpen();
break;
case HomeMenuItem::OPDS_BROWSER:
onOpdsBrowserOpen();
break;
case HomeMenuItem::FILE_TRANSFER:
onFileTransferOpen();
break;
case HomeMenuItem::SETTINGS_MENU:
onSettingsOpen();
break;
default:
break;
}
}
}
}