Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,15 @@ void InkHUD::MenuApplet::onButtonShortPress()
if (!settings->joystick.enabled) {
if (!cursorShown) {
cursorShown = true;
// Select the first item that isn't a header
cursor = 0;
while (cursor < items.size() && items.at(cursor).isHeader) {
cursor++;
}
if (cursor >= items.size()) {
cursorShown = false;
cursor = 0;
}
Comment on lines 1527 to 1535
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “select first non-header item” logic is duplicated in both onButtonShortPress() and onNavDown(). Consider extracting it into a small helper (and similarly for the “select last non-header” logic) to keep cursor-reveal behavior consistent and reduce the chance of future drift when header-handling changes.

Copilot uses AI. Check for mistakes.
} else {
do {
cursor = (cursor + 1) % items.size();
Expand Down Expand Up @@ -1576,7 +1584,15 @@ void InkHUD::MenuApplet::onNavUp()

if (!cursorShown) {
cursorShown = true;
cursor = 0;
// Select the last item that isn't a header
cursor = items.size() - 1;
while (items.at(cursor).isHeader) {
if (cursor == 0) {
cursorShown = false;
break;
Comment on lines +1587 to +1592
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onNavUp() sets cursor = items.size() - 1 without guarding for items.empty(). If the items list is empty (e.g., a transient state during page changes), this underflows and items.at(cursor) will throw/abort. Add an early items.empty() check (and keep cursorShown false) before computing the last index, similar to the defensive handling used in onNavDown()/onButtonShortPress().

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be checked in any of the other places where the cursor moved or set. Should I add this guard everywhere the cursor is moved?

}
cursor--;
}
} else {
do {
if (cursor == 0)
Expand All @@ -1597,7 +1613,15 @@ void InkHUD::MenuApplet::onNavDown()

if (!cursorShown) {
cursorShown = true;
// Select the first item that isn't a header
cursor = 0;
while (cursor < items.size() && items.at(cursor).isHeader) {
cursor++;
}
if (cursor >= items.size()) {
cursorShown = false;
cursor = 0;
}
} else {
do {
cursor = (cursor + 1) % items.size();
Expand Down
Loading