Repository navigation
Conversation
Automated AI review
Outcome: Back after a search lands on the wrong row; Back after a search lands on the wrong row
Suggested change: Save index 0 when leaving a filtered list ( Reproducer (fails at f8b2d1c)Save the test below as #!/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})`
)
JSActual output at the PR head (exit status 1). Merging the PR into the current At the merge base (
|
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>
|
| ) | ||
| 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), |
There was a problem hiding this comment.
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!
|
Thanks for the review. Both points are fixed in aadb1f5:
I also ran your back-navigation reproducer against the branch, and all three assertions pass. |
|
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 |
|
I read this pull request at aadb1f5, including the change to save index 0 when Back leaves a filtered list and the updated Two models classified it separately and disagreed, so it carries no 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. |
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 theselectedIndex. When returning to a previous menu,goBacknow passes the saved index back tosetActiveMenu, preserving the exact cursor position where the user left off.