diff --git a/shell/plugins/menu/Menu.qml b/shell/plugins/menu/Menu.qml index aa879c188fd6..7f99d69edfd8 100644 --- a/shell/plugins/menu/Menu.qml +++ b/shell/plugins/menu/Menu.qml @@ -726,13 +726,17 @@ 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) { + // A filtered list's index means nothing once the filter clears, so a + // menu left mid-search comes back at the top. + root.navStack = root.navStack.concat([{ id: root.activeMenu, index: root.filterText.trim() ? 0 : root.selectedIndex }]) + } root.activeMenu = id root.filterText = "" - root.selectedIndex = 0 + root.selectedIndex = restoreIndex !== undefined ? restoreIndex : 0 root.cursorActive = true if (fromPointer) pointerGate.allowInitialSample() else root.disarmPointer() @@ -747,7 +751,11 @@ 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) + if (typeof previous === "string") { + root.setActiveMenu(previous, false) + } else { + root.setActiveMenu(previous.id, false, false, previous.index) + } return true } diff --git a/test/shell.d/menu-test.sh b/test/shell.d/menu-test.sh index a424379b1afd..375b270b762d 100644 --- a/test/shell.d/menu-test.sh +++ b/test/shell.d/menu-test.sh @@ -491,7 +491,7 @@ 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' ) assert(