Skip to content

Remember highlighted menu item after returning from submenus - #12098

Closed
Teslicek wants to merge 1 commit into
omacom:quattrofrom
Teslicek:fix/menu-remember-selection
Closed

Teslicek wants to merge 1 commit into
omacom:quattrofrom
Teslicek:fix/menu-remember-selection

Conversation

@Teslicek

Copy link
Copy Markdown

Summary

  • preserve the highlighted parent row while navigating into submenus
  • restore by stable item ID, with index clamping as a fallback when rows change
  • reset navigation state when opening a fresh menu or dmenu request

Verification

  • git diff --check
  • bash test/shell.d/menu-test.sh
  • manually verified Down → Right → Left keeps the parent row highlighted in the live Omarchy menu

Fixes the navigation state loss where returning from a submenu always highlighted the first row.

@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: The main path works as described. After entering a submenu with the keyboard or a mouse click, Left/Backspace puts the cursor back on the row that was entered. This holds across nested levels and through link rows. Because the restore looks the row up by item ID, it still finds the right row when rows above it disappear while the submenu is open, where an index-only restore would not. Both open paths (openExistingMenu and openDmenu) reset selectionStack together with navStack. The PR applies cleanly to the current quattro tip, and test/shell.d/menu-test.sh passes on the head and on the tip with the PR applied.

Two small edge cases, a test gap and an optional follow-up are below, plus a note on overlapping open PRs.

Returning from a deeper search result can land on an unrelated row

Search rows include all descendants of the active menu, not only its direct children (Menu.qml:625-650). When a submenu is opened from a deeper result, the saved itemId is that deep ID and the saved index is its position in the filtered list. goBack() rebuilds the parent unfiltered, the deep ID is not a row there, and restoreSelection() falls back to the filtered index clamped into the unfiltered list (Menu.qml:730-743).

root menu, type "style"     filtered list: [0] Style   [1] Install › Style
Down, Right                 enters install.style        saved { index: 1, itemId: "install.style" }
Left                        root list rebuilt unfiltered; "install.style" is not a root row
                            → index 1 → Learn           (base branch: Apps, row 0)

The same happens with font (Install › Style › Font at filtered index 1 → Learn). Results that are direct children of the parent restore correctly (style → Style).

Impact: After drilling into a deeper search result, going back highlights whichever parent row sits at that filtered position, usually unrelated to the path taken. The base branch at least lands predictably on the first row.

Suggested change: Before the index fallback, walk the saved ID up its parent chain until it matches a row of the menu being returned to, so Install › Style comes back to Install. The index fallback then only applies when the row really disappeared.

The restore can put the cursor on a disabled row

restoreSelection() runs after rebuildDisplay() has already settled the cursor, then sets selectedIndex directly and forces cursorActive = true (Menu.qml:743-744). That skips the rule in settleCursor() (Menu.qml:549-553) and docs/menu.md that disabled rows are unselectable ("cursor, pointer, and Enter all step over it").

In a harness with a user-defined submenu row whose disabled: guard turns true while that submenu is open, Left leaves the cursor on the disabled row and Right does nothing. The base branch moves to the next selectable row. From the source, if the parent has no rows at all, cursorActive is still set to true.

Impact: Guards are re-evaluated only on open and on a menu-file reload, so the direct case needs a guard to flip while the submenu is open. The search fallback above could also land on a disabled row, but no case in the default menu was found where the restored row is disabled (every 1- and 2-letter search in Install was scanned with realistic guard states).

Suggested change: Replace the two assignments with root.selectedIndex = restored; root.settleCursor(). The saved cursorActive is then unnecessary: it is always true in practice, because entering a submenu requires an active cursor.

Optional test improvement: The new assertion (test/shell.d/menu-test.sh:614-619) only checks that three source strings exist. With root.selectedIndex = restored deleted, or with the ID lookup disabled, the full menu test still passes (128 ok on the tip with the PR applied). docs/testing.md ("Unit-testing shell JavaScript from bash") describes keeping plugin logic in .js modules so Node can test it. Moving the row resolution into MenuModel.js (for example a restoredRowIndex(items, rowIds, saved) helper, which needs the items map to walk parents) would allow real assertions: ID hit after rows shift, ancestor hit for a deep search result, clamped fallback, empty list and disabled row.

Optional: Menus opened directly on a submenu still return to the parent's first row, because they start with no history and goBack() takes the unchanged no-history branch (Menu.qml:796-798). For example, SUPER+ESCAPE opens System, and Left then highlights Apps rather than System. The same applies to SUPER+CTRL+C, SUPER+CTRL+O and SUPER+CTRL+H. Selecting the row whose ID equals the menu being left, in that branch, would cover it. The PR description says returning from a submenu "always highlighted the first row"; this path still does.

Overlapping open PRs

Several open PRs implement the same "restore the row on back" behaviour: #7074, #7954, #11577, #12644, #12759, #13012 and #13225. On 2026-09-21 an Omarchy team member closed #7657, #7800 and #8322 as duplicates of #7074, asking any reopened PR to include "a note on the difference" (example). This PR was opened earlier and was not part of that sweep. git merge-tree reports a Menu.qml conflict between this PR and each of those seven PRs, and also #12823 (menu navigation memory).


Review information

Test scope: Source review of the pinned head 7401a4a3, plus isolated runs of test/shell.d/menu-test.sh on the merge base, the head, the current quattro tip and the tip with the PR applied. Navigation behaviour was exercised with a Node harness that evaluates the real Menu.qml function bodies against the real default menu file, with a mocked list model and stubbed QML objects. Mutation checks were run on the test. No live Quickshell session was used, so rendering and scroll-into-view were not observed, and the author's manual check was not reproduced on a desktop. The disabled-row case used a synthetic user-defined menu. The related-PR search covered the newest 1000 open PRs by changed files plus keyword searches across all open PRs.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for this, @Teslicek. Remembering the highlighted row on the way back from a submenu is a real fix, and saving the item ID rather than only the index is the right instinct. However, seven other open pull requests fix the same bug in Menu.qml: #7074, #7954, #11577, #12644, #12759, #13012 and #13225. Only one of them can land, so I compared all eight against quattro (8b4eae66) before running any of them on a worker.

#12644 is the one I'm carrying forward. This pull request doesn't cover three cases that #12644 handles:

  • Deep search results. Search rows include descendants several levels down. Entering Install › Style from a root search for "style" saves install.style at filtered index 1. That ID isn't a row in the unfiltered root, so restoreSelection() falls back to index 1 and lands on Learn. Return the menu cursor to the entered row when going back #12644 walks the saved ID up its parent chain and lands on Install.
  • Disabled rows. restoreSelection() sets selectedIndex and forces cursorActive = true after rebuildDisplay() has already settled the cursor. This skips the rowSelectable() rule, so the cursor can land on a disabled row, or become active in an empty list. Return the menu cursor to the entered row when going back #12644 only moves the cursor to a selectable row and otherwise leaves it where settleCursor() put it.
  • Menus opened straight into a submenu. SUPER+ESCAPE, for example, has no history. goBack() takes the unchanged no-history branch, so going back still highlights the first row. Return the menu cursor to the entered row when going back #12644 selects the submenu's own row in the parent.

#12644 also keeps the ancestor lookup in MenuModel.js, where Node can test it. The test added here only checks that three source strings exist.

Both reviews were source reviews, and I didn't run this branch on a worker, because it won't be the fix carried forward. A second opinion from Codex Medium reviewed all eight pull requests without being given my answer. It also picked #12644, ranked this one seventh, and found the same three gaps. Its independence isn't guaranteed. Whether #12644 lands is the maintainer's decision, and nothing here waits on you.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thank you for this, @Teslicek. #12644 fixes the same problem and also handles a case this one misses, as the review above explains, so this is closed in favour of it. If it does not cover your case, please say so there.

Closed at the maintainer's request. The review comment above has the details; it was done by Claude Opus 5.5 with Codex Medium as a second opinion, whose agreement is not independent.

@omarchybot omarchybot closed this Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants