Skip to content
Closed
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions shell/plugins/menu/Menu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Item {
property int applySerial: 0
property var items: ({})
property var itemOrder: []
// Each entry is { menu, selectedIndex } so going back lands the cursor
// where it was when the submenu was entered, not back at the top.
property var navStack: []
property var providersLoaded: ({})
property var providerQueue: []
Expand Down Expand Up @@ -726,13 +728,15 @@ Item {
root.rebuildDisplay()
}

function setActiveMenu(id, pushHistory, fromPointer) {
function setActiveMenu(id, pushHistory, fromPointer, restoreIndex) {
panel.freezeCardTop()
if (!root.item(id)) id = "root"
if (pushHistory && id !== root.activeMenu) root.navStack = root.navStack.concat([root.activeMenu])
if (pushHistory && id !== root.activeMenu) {
root.navStack = root.navStack.concat([{ menu: root.activeMenu, selectedIndex: root.selectedIndex }])
}
root.activeMenu = id
root.filterText = ""
root.selectedIndex = 0
root.selectedIndex = (restoreIndex === undefined || restoreIndex < 0) ? 0 : restoreIndex
root.cursorActive = true
if (fromPointer) pointerGate.allowInitialSample()
else root.disarmPointer()
Expand All @@ -747,7 +751,7 @@ Item {
if (root.navStack.length > 0) {
var previous = root.navStack[root.navStack.length - 1]
root.navStack = root.navStack.slice(0, root.navStack.length - 1)
root.setActiveMenu(previous, false)
root.setActiveMenu(previous.menu, false, false, previous.selectedIndex)
return true
}

Expand Down
16 changes: 15 additions & 1 deletion test/shell.d/menu-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,23 @@ assert(
'menu filter changes disarm pointer selection'
)
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),
'menu route changes only accept an initial pointer sample for mouse activation'
)
// Drilling into a submenu remembers where the cursor was, and going back
// restores it instead of dropping the user at the top of the list again.
assert(
/root\.navStack = root\.navStack\.concat\(\[\{ menu: root\.activeMenu, selectedIndex: root\.selectedIndex \}\]\)/.test(menuQml),
'menu remembers the cursor row when drilling into a submenu'
)
assert(
/root\.selectedIndex = \(restoreIndex === undefined \|\| restoreIndex < 0\) \? 0 : restoreIndex/.test(menuQml),
'menu restores a remembered cursor row instead of always starting at the top'
)
assert(
/root\.setActiveMenu\(previous\.menu, false, false, previous\.selectedIndex\)/.test(menuQml),
'menu goes back to the remembered cursor row of the parent menu'
)
assert(
/\(event\.key === Qt\.Key_Backspace \|\| event\.key === Qt\.Key_Left\) && !root\.filterText[\s\S]*root\.goBack\(\)/.test(menuQml),
'menu Left key follows empty-filter Backspace navigation'
Expand Down