Skip to content

Restore menu selection when navigating back - #13012

Open
onurersel wants to merge 1 commit into
omacom:quattrofrom
onurersel:fix/menu-back-selection
Open

onurersel wants to merge 1 commit into
omacom:quattrofrom
onurersel:fix/menu-back-selection

Conversation

@onurersel

@onurersel onurersel commented Sep 23, 2026 •

Copy link
Copy Markdown

Summary

  • Restore the selected parent row when navigating back from a submenu with Left Arrow or Backspace.
  • Track the selected item by ID so the cursor follows it if parent rows reorder while the submenu is open.
  • Add focused regression tests for both behaviors.

Screen capture

before

screenrecording-2026-09-23_08-48-09.mp4

after

screenrecording-2026-09-23_08-44-13.mp4

Testing

  • bash test/shell.d/menu-test.sh — passed
  • git diff --check — passed

Before marking ready

  • Verify Enter → Left Arrow and Enter → Backspace in a running Omarchy Shell. The graphical session was unavailable during development.

@onurersel
onurersel marked this pull request as ready for review September 23, 2026 06:49
@llstrk

llstrk commented Sep 24, 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: in the tested scope, Back (Left, or Backspace with an empty filter) now returns the cursor to the parent row used to open the submenu. The restore works for keyboard and mouse entry and at each level of a nested history. It also follows the row by id when other parent rows are hidden while the submenu is open. If the saved row became disabled, the cursor moves to the next selectable row. One edge case remains for submenus opened from search results.

Flow (default menu, harness run of the production functions) Base: cursor after Back Head: cursor after Back
Root, cursor to Style, Enter, Back Apps Style
Root › Setup › Defaults › Browser, Back three times first row each time Browser, Defaults, Setup
Enter Install while guarded rows above it are hidden, Back Apps Install
Click Update with the keyboard cursor on Apps, Back Apps Update

Back after opening a deeper search result lands on an unrelated row

With a filter active, the list includes matching submenus from deeper levels. When one of those is opened, setActiveMenu saves the filtered-list index and the deeper row's id. Back clears the filter and rebuilds the parent with only its own rows, so the id lookup finds no match. The filtered index is then applied to the unfiltered list.

root, filter "browser"          saved on Enter
  0  Setup › Defaults › Browser
  1  Install › Browser   <-- Enter   { index: 1, itemId: "install.browser" }
  2  Remove › Browser

Back: filter cleared, root rebuilt unfiltered
  0  Apps
  1  Learn               <-- cursor (id not found, index 1 reused)
  ...
  5  Install             (row the submenu belongs under)

Observed with the default menu and no installed-app search results (installed apps can add results and shift the exact row). The base branch puts the cursor on the first row in the same flow. Search results that are direct children of the current menu, such as style from the top level, restore correctly.

Impact: cursor position only, with no wrong action. The search, open, Back flow ends on a row unrelated to the one chosen, which is less predictable than the previous first-row behavior.

Suggested change: when the picked row is not a direct child of the menu being left, save its ancestor that is (so Back lands on Install), or skip the index fallback when a filter was active. These approaches were not tested.

Optional test improvement: the reorder assertion in test/shell.d/menu-test.sh moves style to index 0, which is also where the base code always puts the cursor, so that assertion alone passes against base. Moving the tracked row to a nonzero index other than the saved one (for example [apps, style, learn], expecting 1) makes it fail on base and pass on head.


Review information

Test scope: Source review of head 7a7fb10 against base quattro (d3cfd53). The repository menu test passed on head and base in an isolated sandbox, using Deno's Node compatibility in place of Node. A harness ran the production navigation functions from both revisions against the default menu, with rendering, providers and the pointer gate stubbed. No running Omarchy Shell or graphical session was used, so row highlighting and scroll-into-view were assessed from source only.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, Opus 5.5 Medium editorial check.

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

@buger buger left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: approve-with-comments — mechanics verified against source and by driving the real shell; three comments and three suggested tests below.

The attached 71-second narrated video shows the behavior difference live: the real omarchy shell running under Quickshell with the stock menu, keys sent through a virtual keyboard. Control (the PR's base d3cfd53): Down twice to Trigger (row 2), Return into its submenu, Back — the cursor lands on row 0 (Apps), the drilled-from row is lost. On this PR's head (7a7fb10): Back restores the cursor to Trigger, row 2 — the nav stack now records the row's index and item id, not just the menu.

pr-13012-restore-selection.mp4

Hazards I specifically checked (all clear):

  • Out-of-range restore index cannot crash: restoreSelection.index may exceed the rebuilt model, but rebuildDisplay() ends in settleCursor() → nextSelectable(from, 1) (Menu.qml:530), which modulo-normalizes and returns −1 for empty/disabled models. Traced both functions.
  • No other navStack consumers that could trip on the new record shape: the only readers are the push (734), the pop (762–764), and the two resets (859, 887). The dmenu paths reset navStack = [], so the record shape never leaks into the select flow.
  • Pointer hygiene: fromPointer gating untouched; disarmPointer() still runs on keyboard-driven restores, so a stale mouse position can't steal selection.
  • Disabled/vanished rows degrade sanely: the rowSelectable(i) guard skips a disabled remembered row; a vanished row falls back to the settled index — except after a search, where that index points into the filtered list (comment 3).
  • Ordering: the push captures the outgoing menu's cursor before activeMenu reassigns — correct in the diff.

Comments:

  1. The new test's extraction regex is brittle — and I can prove it. Pulling setActiveMenu/goBack out of Menu.qml with / function setActiveMenu\([\s\S]*?\n \}\n\n function goBack\([\s\S]*?\n \}/ assumes the two functions sit exactly one blank line apart in that order. When I applied this PR to my working copy (which has comments between those functions), the new test null-deref'd (TypeError, rc=1) on first run — the failure mode is a regex null deref, not a clean assertion. Please match each function independently, or assert match() non-null with a descriptive message before slicing.

  2. Cursor-vs-provider drift (worth a code comment, not a blocker). loadProviderForMenu(id) runs after the restore scan, and asynchronously arriving provider rows trigger a later rebuildDisplay() whose settleCursor() follows the index, not the id — a volatile provider reshaping rows above the remembered row can drift the cursor off it. Same shape as pre-existing behavior on any rebuild, but a comment at the restore scan would stop future readers assuming id-tracking survives async row arrival.

  3. Back after opening a deeper search result lands on an unrelated row (@llstrk's report, reproduced on this head). The restore itself works, including after a search whose result is a direct child of the current menu: inside Style, search font, open Font, and Back lands on Font. It goes wrong only when the result sits deeper than the menu being left. Search font, Enter on Install › Style › Font, then Back: the cursor lands on Learn (root row 1); quattro gives row 0 (Apps). The saved index points into the filtered list, but Back shows the unfiltered one. Remember the selected row's ancestor that is a direct child of the menu being left, not the filtered index. The climb is capped at 32 like isDescendantOf, so a parent cycle in a user extension can't hang it. menu-test.sh still passes, and Back lands on Install:

       var selectedRow = root.selectedIndex >= 0 && root.selectedIndex < displayModel.count ? displayModel.get(root.selectedIndex) : null
+      // A search result can sit deeper than this menu, and Back clears the
+      // filter: remember the row Back will show, not the filtered index.
+      // Bounded like the other parent walks, so a parent cycle can't hang.
+      var selectedId = selectedRow ? selectedRow.itemId : ""
+      for (var up = 0; up < 32 && selectedId && root.item(selectedId) && root.item(selectedId).parent !== root.activeMenu; up++)
+        selectedId = root.item(selectedId).parent
       root.navStack = root.navStack.concat([{
         menu: root.activeMenu,
-        index: root.selectedIndex,
-        itemId: selectedRow ? selectedRow.itemId : ""
+        index: root.filterText ? 0 : root.selectedIndex,
+        itemId: selectedId
       }])

A rarer form of the same stale index: if the parent menu is removed from the user file while you're below it, setActiveMenu falls back to root and applies the child menu's index there, so Back lands on an unrelated root row. Ignoring restoreSelection when the target menu no longer exists covers that (if (!root.item(id)) { id = "root"; restoreSelection = null }).

A test for the same harness (after the reorder assertion): fails on this head, passes with the change

It fails on this head (expected: install / actual: learn) and passes with the change:

// Back after opening a search result that sits deeper than the current menu.
const parents = { install: 'root', 'install.style': 'install', 'install.style.font': 'install.style' }
const shallowItem = navRoot.item
navRoot.item = id => parents[id] ? { parent: parents[id] } : shallowItem(id)
menuRows.root = [{ itemId: 'apps' }, { itemId: 'learn' }, { itemId: 'install' }]
menuRows['install.style.font'] = []
navRoot.filterText = 'font'
visibleRows = [{ itemId: 'style.font' }, { itemId: 'install.style.font' }]
navRoot.selectedIndex = 1
navRoot.setActiveMenu('install.style.font', true)
navRoot.goBack()
assertEqual(visibleRows[navRoot.selectedIndex].itemId, 'install', 'menu Back from a deeper search result lands on the row it belongs under')
Real-function check against the default menu

Run from the repo root with node back-from-search.js:

const fs = require('fs'), path = require('path'), vm = require('vm')
const m = require(path.resolve('shell/plugins/menu/MenuModel.js'))
const qml = fs.readFileSync('shell/plugins/menu/Menu.qml', 'utf8')
const fn = n => qml.match(new RegExp('\\n  function ' + n + '\\([^)]*\\) \\{[\\s\\S]*?\\n  \\}\\n'))[0]
const g = m.mergeMenuSources(m.parseMenuJsonc(fs.readFileSync('default/omarchy/omarchy-menu.jsonc', 'utf8')), [])
const rows = []
const displayModel = { clear() { rows.length = 0 }, append(x) { rows.push(x) }, get count() { return rows.length }, get(i) { return rows[i] } }
const r = {
  dmenuActive: false, rowsLoaded: true, activeMenu: 'root', filterText: '', searchDivider: false, navStack: [],
  selectedIndex: 0, cursorActive: true, items: g.items, itemOrder: g.itemOrder, whenResults: {}, disabledResults: {}, checkedResults: {},
  item(id) { return this.items[id] || null },
  isDescendantOf(id, a) { return m.isDescendantOf(this.items, id, a) },
  isVisible(e) { return m.isVisible(this.items, this.itemOrder, this.whenResults, e) },
  isDisabled(e) { return m.isDisabled(this.disabledResults, e) },
  matchesQuery(e, q) { return m.matchesQuery(e, q, this.isVisible(e) && !this.isDisabled(e)) },
  parentPathFor(id) { return m.parentPathFor(this.items, id) },
  searchScore(e, q) { return m.searchScore(this.items, e, q) },
  displayRow(e, d, s, sec) { return m.displayRow(this.items, this.itemOrder, this.checkedResults, this.disabledResults, e, d, s, sec) },
  revealCursor() {}, disarmPointer() {}, invalidateVolatileProvider() {}, loadProviderForMenu() {}
}
const names = ['setActiveMenu', 'goBack', 'rebuildDisplay', 'settleCursor', 'nextSelectable', 'rowSelectable']
const fns = vm.runInNewContext(`(function() { ${names.map(fn).join('\n')}; return { ${names.join(', ')} } })()`,
  { root: r, displayModel, layoutSerial: 0, Qt: { callLater() {} }, panel: { freezeCardTop() {} }, pointerGate: { allowInitialSample() {} } })
for (const n of names) r[n] = fns[n].bind(r)

r.filterText = 'font'
r.rebuildDisplay()
r.selectedIndex = rows.findIndex(x => x.itemId === 'install.style.font')
console.log('search "font", Enter on row', r.selectedIndex, '(install.style.font)')
r.setActiveMenu('install.style.font', true)
r.goBack()
console.log('after Back: cursor on row', r.selectedIndex, '=', rows[r.selectedIndex].itemId)
Tree After Back
quattro 8b4eae6 row 0 = apps
this head 7a7fb10 (also merged onto 8b4eae6) row 1 = learn
this head + the change above row 5 = install
Test results: fails on this head, green with the fix, and safe on a parent cycle
Run Result
this head + the new test exit 1 — expected: install / actual: learn
this head + the fix + the new test exit 0, 124 ok
this head + the fix only exit 0, 123 ok
a parent cycle in a user extension, with the fix terminates (the climb is capped at 32)
the same cycle with an unbounded walk hangs (times out)

Suggested additional tests (the new ones cover the happy paths well — these pin the degrade paths, which are where this feature can quietly regress):

Test Why
Remembered row now disabled → cursor settles on nearest selectable row, never the disabled one pins the rowSelectable guard
Remembered id absent → cursor lands at clamped old index, not 0, no crash — except after a search: there the old index is the cause of comment 3, so don't pin it for that case pins the degrade path of the scan
goBack with empty nav stack → falls back to parent menu with cursor at 0 fallback behavior under the new record shape

Verified by driving the real shell on a live Omarchy/Quickshell session; the video above is the actual run.

Independent verification: the requirement map and change-impact analysis for this PR.


Updated 2026-10-02: added comment 3 (Back after a deeper search result) with a bounded fix and a failing test; line numbers for this head; new video.

buger added a commit to probelabs/omarchy that referenced this pull request Oct 1, 2026
…attro-proof

Brings only the new artifacts from archive/2026-10-01/media-on-forkfixes
(d79155c), re-based onto the clean upstream-code branch:
- agents/skills/headless-gui-testing.md (new guide; upstream files untouched)
- review/media/: five clips + MANIFEST.md
- pocs/reproducers/<clip>/: drivers, fixtures, READMEs; run-at-rev.sh runs
  them against explicit SHAs from the git object store

Every rev reference is now an explicit SHA (8b4eae6/e332dc97 upstream,
f75205f PR omacom#13512 head, ff77cd0 consolidated fix, d3cfd53/7a7fb10c
PR omacom#13012), with per-SHA output re-run on the audit box. Adds a
full-line-comment control fixture (upstream 3 rows, f75205f 0, ff77cd0 3).
Box paths parametrized via PROOF_ENV_DIR. Clean-product-diff allowlist
gains the one added guide file.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
buger added a commit to probelabs/omarchy that referenced this pull request Oct 2, 2026
- Front page: omacom#9057 row says omacom#9056 fixes the re-summon trigger only (a menu
  process that dies mid-request still strands the caller); omacom#13492 row says
  label-only array elements stay hidden; omacom#13493 row says every entry in that
  file; omacom#13250 row covers actions; omacom#10340 reproduces but is a ranking-policy
  change (omacom#12223).
- Clip notes: this branch carries upstream 821ae58 (was e332dc9); ff77cd0 is
  the first commit of omacom#13968 (head b2dae8d), with the reproducers re-run on
  821ae58 and b2dae8d; no internal branch names; the omacom#13012 back-from-search
  note names the KI-MENU-BACK-FILTERED-INDEX test instead of a removed script.
@omarchybot omarchybot added the bug Something isn't working label Oct 3, 2026
buger added a commit to probelabs/omarchy that referenced this pull request Oct 4, 2026


Upstream PR product code (Menu.qml) and the PR's own menu-test.sh hunk,
applied onto quattro-proof with a 3-way merge against the change base
d3cfd53. One conflict, resolved as on the previous mirror: the baseline's
// Implements: SW-REQ-260922-DE93 line sits directly above the PR's changed
setActiveMenu signature; both are kept. The product diff against the PR
merged onto quattro f45461a is behaviour-neutral annotations only, and the
menu-test.sh hunk is identical to the PR's.

Proof-Change-Key: pr/13012
Proof-Upstream-Repo: github.com/omacom/omarchy
Proof-Mirror-Of: refs/pull/13012/head
Proof-Upstream-Head: 7a7fb10
Proof-Head-Ref: fix/menu-back-selection
Proof-Change-Base: d3cfd53
Proof-Base-Ref: quattro
Proof-Baseline: 1e43373
Proof-Baseline-Ref: quattro-proof
Proof-Previous-Mirror: c9d42a2

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
buger added a commit to probelabs/omarchy that referenced this pull request Oct 4, 2026
…de the body

PR omacom#13012's own vm-test (menu-test.sh) extracts setActiveMenu+goBack with a
regex that requires goBack to follow setActiveMenu after exactly one blank
line; the baseline's annotation comment between them made the regex return
null and the whole menu-test.sh crash (TypeError, not an assertion). Trace
links are file-level, so the annotation is relocated into goBack's body
(binds to the enclosing function). PR product/test code untouched; the
fragility is recorded as a review finding.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
buger added a commit to probelabs/omarchy that referenced this pull request Oct 4, 2026
…tro-proof 1e43373)

Mirror of omacom#13012 at head 7a7fb10: the upstream change applied onto
quattro-proof 1e43373, followed by the proof work for the review. This
commit changes no file; it records the mirror at the branch tip, where the
review pipeline reads it (Proof-* trailers).

Proof-Change-Key: pr/13012
Proof-Upstream-Repo: github.com/omacom/omarchy
Proof-Mirror-Of: refs/pull/13012/head
Proof-Upstream-Head: 7a7fb10
Proof-Head-Ref: fix/menu-back-selection
Proof-Change-Base: d3cfd53
Proof-Base-Ref: quattro
Proof-Baseline: 1e43373
Proof-Baseline-Ref: quattro-proof
Proof-Previous-Mirror: a60c47d
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for this, @onurersel. Tracking the selected row by id is the right fix for the reorder case. Several other open pull requests fix the same Back behaviour, though, so I compared them all instead of verifying this one alone. Nothing was run on a worker, because verifying a fix that will not be merged in this form would not tell the maintainer anything new.

The one I'm recommending is #12644. It is older than this one, and it also handles two cases this one misses:

  • Back after opening a deeper search result. For example: type font at the root, press Enter on Install › Style › Font, then go Back. This pull request finds no row with Font's id in the unfiltered root menu, so it falls back to the index from the filtered list and puts the cursor on an unrelated row (Learn). That is the case @llstrk and @buger reported above. Return the menu cursor to the entered row when going back #12644 climbs from the opened item up through its parents until it reaches a row in the menu being shown, so Back lands on Install (nearestRowIndex in MenuModel.js).
  • A menu opened straight into a submenu, with no history. Here this pull request puts the cursor on the parent's first row. Return the menu cursor to the entered row when going back #12644 puts it on the submenu's own row.

The older pull requests #7074 and #11577 restore only an index, so they land on the wrong row when the parent's rows are hidden or reordered. #7954 and #12759 also bring back the search filter on Back, which is a behaviour change beyond the fix. #13225 matches by id exactly, the same way this pull request does.

Codex Medium reviewed all seven separately and also chose #12644. It found nothing in this pull request that #12644 lacks and should take on. Note that its independence is not guaranteed, since it could read this session's reasoning. Its verdict came from reading the source: nothing was run.

This now waits on the maintainer to choose among the competing fixes. If #12644 is merged, this one can be closed.

@paulogeyer

Copy link
Copy Markdown
Contributor

I reviewed the open PRs that restore the menu selection when going back (no linked issue). This is code review only, because the menu tests need a running compositor.

PR restores by merges cleanly test
#13012 item id, falling back to index yes yes
#13225 item id, keyboard selection only yes none
#7074 index only yes yes
#7954, #12759 no (conflicts)

I'd go with #13012. It saves the selected item's id with each history entry, restores it after the parent menu rebuilds, skips rows that can't be selected, and falls back to the old index. #13225, #7074, #7954 and #12759 duplicate it. #7074's index-only restore lands on the wrong row whenever the parent menu's rows change.

Suggestion for #13012: menus filled by a provider load after the restore runs, so it only gets the index fallback there. A second lookup once the provider finishes would cover them.

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.

5 participants