Skip to content

Fix menu navigation history unconditionally resetting cursor index - #11577

Open
Lifferado wants to merge 2 commits into
omacom:quattrofrom
Lifferado:fix/menu-navigation-history
Open

Lifferado wants to merge 2 commits into
omacom:quattrofrom
Lifferado:fix/menu-navigation-history

Conversation

@Lifferado

Copy link
Copy Markdown

Currently, when navigating backwards through the omarchy menu submenus (e.g., using Left Arrow or Backspace), the cursor position is unconditionally reset to the top of the menu (index 0).

This PR fixes that behavior by modifying the navigation history stack (navStack) to store both the menu ID and the selectedIndex. When returning to a previous menu, goBack now passes the saved index back to setActiveMenu, preserving the exact cursor position where the user left off.

@llstrk

llstrk commented Oct 1, 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.

Outcome: Back after a search lands on the wrong row; menu-test.sh fails.

Back after a search lands on the wrong row

setActiveMenu saves the filtered-list index, then clears the filter, so goBack applies it to the parent's unfiltered rows. After searching font at the root and opening the second result (Install's Font), Left lands on Learn (row 1), not row 0 as before. Impact: Enter right after Back activates a row the user never chose.

Suggested change: Save index 0 when leaving a filtered list (index: root.filterText.trim() ? 0 : root.selectedIndex), or restore by row id, falling back to the entered branch.

Reproducer (fails at f8b2d1c)

Save the test below as test/shell.d/menu-back-test.sh in a checkout of the PR head (f8b2d1c2) and run it with bash test/shell.d/menu-back-test.sh (it needs node, like menu-test.sh). It runs the menu's own functions from Menu.qml against the shipped omarchy-menu.jsonc. Only QML-only objects (ListModel, ListView, panel, pointer gate, processes) are stubbed. Guard results are empty (every row visible and enabled) and no app or font-provider rows are loaded.

#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

run_node_test <<'JS'
const fs = require('fs')
const vm = require('vm')
const MenuModel = requireFromRoot('shell/plugins/menu/MenuModel.js')
const menuQml = fs.readFileSync(path.join(root, 'shell/plugins/menu/Menu.qml'), 'utf8')
const jsonc = fs.readFileSync(path.join(root, 'default/omarchy/omarchy-menu.jsonc'), 'utf8')

// Load the menu's own functions against the shipped menu, with the QML-only
// objects (ListModel, ListView, panel, pointer gate, processes) stubbed.
const rows = []
const later = []
const displayModel = {
  get count() { return rows.length },
  clear() { rows.length = 0 },
  append(row) { rows.push(Object.assign({}, row)) },
  get(index) { return rows[index] }
}
const menu = {
  mode: 'menu', activeMenu: 'root', filterText: '', selectedIndex: 0, cursorActive: false,
  opened: false, rowsLoaded: false, requestActive: false, requestSerial: 0, applySerial: 0,
  selectionFile: '', doneFile: '', searchDivider: false, layoutSerial: 0, pendingInitialMenu: 'root',
  items: {}, itemOrder: [], navStack: [], providersLoaded: {}, providerQueue: [], providers: {},
  whenResults: {}, checkedResults: {}, disabledResults: {}, appLibrary: null,
  get dmenuActive() { return this.mode === 'select' || this.mode === 'input' }
}
const functions = menuQml.match(/^  function \w+\([^)]*\) \{(?:[^\n]*\}$|[\s\S]*?\n  \}$)/gm)
vm.runInNewContext(`with (root) {\n${functions.map(fn => `root.${fn.trim().match(/^function (\w+)/)[1]} = (${fn.trim()})`).join('\n')}\n}`, {
  root: menu, MenuModel, displayModel, Qt: { callLater(fn) { later.push(fn) } },
  ListView: {}, resultList: { positionViewAtIndex() {}, itemAtIndex() { return null } },
  panel: { freezeCardTop() {} }, pointerGate: { reset() {}, allowInitialSample() {} },
  keyCatcher: { forceActiveFocus() {} }, providerProc: {}
})
menu.evaluateGuards = () => {}
const settle = () => { while (later.length) later.shift()() }
const cursorRow = () => rows[menu.selectedIndex].itemId
const moveTo = id => { while (cursorRow() !== id) menu.select(1); settle() }
const enter = () => { menu.activateIndex(menu.selectedIndex); settle() }
const back = () => { menu.goBack(); settle() }
const type = text => { for (const ch of text) menu.setFilter(menu.filterText + ch); settle() }

menu.defaultMenuItems = MenuModel.parseMenuJsonc(jsonc)
menu.userMenuItems = []
menu.rebuildItemsFromSources()

menu.openRoute('root'); settle()
moveTo('style'); enter(); back()
assertEqual(cursorRow(), 'style', 'menu back returns the cursor to the row that was entered')

// Search from the root menu and open the second "Font" result, which lives
// under Install. Back clears the search, so the cursor has to land on that
// branch or the top row, not on whatever row shares the result's position.
menu.openRoute('root'); settle()
type('font')
assertEqual(rows[1].itemId, 'install.style.font', 'menu search lists Install > Style > Font second for "font"')
moveTo('install.style.font'); enter(); back()
assert(
  ['install', rows[0].itemId].includes(cursorRow()),
  'menu back from a search result does not land on an unrelated row',
  `cursor landed on: ${cursorRow()} (row ${menu.selectedIndex})`
)
JS

Actual output at the PR head (exit status 1). Merging the PR into the current quattro (8b4eae66) gives the same output:

ok - menu back returns the cursor to the row that was entered
ok - menu search lists Install > Style > Font second for "font"
cursor landed on: learn (row 1)
not ok - menu back from a search result does not land on an unrelated row

At the merge base (31bd80da) the first assertion fails (expected: style, actual: apps), because the base does not restore the row. With the PR plus a one-line change that saves index 0 when the menu being left is filtered (index: root.filterText.trim() ? 0 : root.selectedIndex), all three assertions pass and test/shell.d/menu-test.sh also passes once its signature regex is updated.

test/shell.d/menu-test.sh fails

Lines 493-496 match the old 3-parameter setActiveMenu signature, so the file exits 1 and its last 27 checks never run.

Suggested change: Add , restoreIndex to that regex; the file then passes.

Reproducer (fails at f8b2d1c)

Run the existing menu test from a checkout of the PR head (f8b2d1c2). Merging the PR into the current quattro (8b4eae66) gives the same failure.

$ bash test/shell.d/menu-test.sh
...
ok - menu ties the cursor to a selectable row existing, both ways
ok - menu filter changes disarm pointer selection
not ok - menu route changes only accept an initial pointer sample for mouse activation
$ echo $?
1

The assertion at test/shell.d/menu-test.sh lines 493-496 matches the literal signature function setActiveMenu\(id, pushHistory, fromPointer\), which the new restoreIndex parameter no longer matches. The file exits at its first failure, so the 27 checks after it do not run. At the merge base (31bd80da) the same file passes all 121 checks.

Updating that regex to function setActiveMenu\(id, pushHistory, fromPointer, restoreIndex\) makes the file pass again at the PR head (121 checks, exit 0).

Details

Verified:

  • Back after entering a submenu from an unfiltered list, by keyboard or click, returns the cursor to the entered row at every level of nested history, and the list is positioned on it.
  • When the menu is summoned straight into a submenu (no history), Back still lands on row 0, as before.
  • The PR merges cleanly into current quattro; menu-guards-test.sh, menu-plugin-test.sh, menu-images-test.sh and keybindings-menu-test.sh pass there.

Search case limits: The run loads no app rows. An installed app with font as a whole word in its name (for example Font Manager) would sort first and shift the exact rows; the wrong-row mechanism is the same.

Optional test improvement: With only the regex fixed, menu-test.sh still passes when the restored index is reverted to 0 (checked with a mutant), so it does not cover this feature. The first assertion of the search reproducer fails at the merge base and passes at the head, so it can serve as that test.

Related open PRs: #7074 uses the same design ({ id, index } entries and a restoreIndex parameter); a maintainer closed #7800 as a duplicate of #7074 to consolidate review. #7954, #12644, #12759, #13012 and #13225 change the same back-navigation code and conflict textually with this PR. #12644 restores by row id, and #7954 restores the search and then the row by id; both avoid the search case above. Open PR #12823 (short-term menu memory) keeps navStack across reopen but filters its entries as string menu ids, so on the merged heads its reopen discards this PR's { id, index } history; one of the two would need adapting if both land.


Review information

Test scope: Source, menu tests and sandboxed headless runs of the real Menu.qml functions at f8b2d1c2; no live desktop.

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 omarchybot added the enhancement New feature or request label Oct 3, 2026
setActiveMenu saved the filtered list's index and then cleared the
filter, so Back applied it to the parent's unfiltered rows: searching
"font" at the root and opening Install's Font, Back landed on Learn.
Save index 0 when the menu being left is filtered, as before this
change.

Also match the new restoreIndex parameter in menu-test.sh's
setActiveMenu signature check, which stopped the file at that
assertion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Menu navigation history now preserves cursor position.

The PR appears safe to merge, with a non-blocking gap in regression tests.

Findings

  1. P2 Cursor restoration lacks test coverage ▶

Summary

The PR saves each menu’s cursor index in navStack and restores it on Back.

  • Going back returns you to the menu row you left.

Reviews (1) · Last reviewed commit: "Restore the top row when Back leaves a f..." · Reviewed by Greptile

Comment thread test/shell.d/menu-test.sh
)
assert(
/function setActiveMenu\(id, pushHistory, fromPointer\)[\s\S]*if \(fromPointer\) pointerGate\.allowInitialSample\(\)\s*else root\.disarmPointer\(\)/.test(menuQml),
/function setActiveMenu\(id, pushHistory, fromPointer, restoreIndex\)[\s\S]*if \(fromPointer\) pointerGate\.allowInitialSample\(\)\s*else root\.disarmPointer\(\)/.test(menuQml),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Cursor restoration lacks test coverage

The updated assertion only checks the new setActiveMenu signature and pointer behavior. It would still pass if goBack stopped restoring previous.index. Add regression checks for saving and restoring a nonzero index, nested Back navigation, and returning to index 0 after leaving a filtered menu.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@Lifferado

Copy link
Copy Markdown
Author

Thanks for the review. Both points are fixed in aadb1f5:

  • Back after a search: setActiveMenu now saves index 0 when the menu being left is filtered (index: root.filterText.trim() ? 0 : root.selectedIndex). Back from a search result lands on the top row, as before this PR, and Back from an unfiltered list still returns to the entered row. I went with the smaller change rather than restoring by row id, to keep this PR focused.
  • menu-test.sh: the setActiveMenu signature regex now includes restoreIndex, and the file passes again (121 checks, exit 0).

I also ran your back-navigation reproducer against the branch, and all three assertions pass.

@jandrusk

Copy link
Copy Markdown

Small focused fix — looks good. Overlaps #12759 which also preserves position/search on back; please either rebase onto that or confirm they compose cleanly so we don't get competing navStack shapes (string vs {id,index}).

@omarchybot omarchybot removed the enhancement New feature or request label Oct 14, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

I read this pull request at aadb1f5, including the change to save index 0 when Back leaves a filtered list and the updated setActiveMenu regex in test/shell.d/menu-test.sh. Nothing was run on a worker yet.

Two models classified it separately and disagreed, so it carries no bug or enhancement label for now. Claude Opus 5.5 read it as an enhancement: on quattro, setActiveMenu sets selectedIndex = 0 on every route change, so landing on the top row after Back is how the menu is written to behave, and remembering the row is new behaviour. Codex Medium read it as a bug: the cursor losing its place on Back is the menu doing the wrong thing.

Which one it is decides what happens next. A bug fix gets reproduced and verified on a worker, while a feature waits until a maintainer asks for it. So this waits on a maintainer to settle the classification. Nothing is needed from you in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants