Repository navigation
Return the menu cursor to the entered row when going back #12644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kmpeeduwee
wants to merge
4
commits into
omacom:quattro
Choose a base branch
from
kmpeeduwee:menu-back-keeps-cursor
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
566b926
Return the menu cursor to the entered row when going back
kmpeeduwee c59d064
Merge quattro into menu-back-keeps-cursor
omarchybot 0565cfd
Merge quattro into menu-back-keeps-cursor
omarchybot 06ff768
Test that going back in the real menu lands on the entered row
omarchybot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import QtQuick | ||
| import Quickshell | ||
|
|
||
| // Back out of Appearance, entered from the root menu and then summoned straight | ||
| // into, must leave the cursor on Appearance rather than the first row. | ||
| ShellRoot { | ||
| id: root | ||
|
|
||
| readonly property string resultPath: Quickshell.env("OMARCHY_QML_TEST_RESULT") | ||
| property var menu: null | ||
| property var list: null | ||
| property int waited: 0 | ||
| property string stage: "open" | ||
|
|
||
| function finish(failure) { | ||
| var payload = JSON.stringify({ ok: !failure, failures: failure ? [failure] : [] }) | ||
| Quickshell.execDetached(["bash", "-c", "printf '%s' \"$1\" >\"$2\"", "bash", payload, resultPath]) | ||
| if (menu) menu.close() | ||
| } | ||
|
|
||
| function findList(item) { | ||
| if (item.indexAt && item.itemAtIndex && item.model) return item | ||
| for (var i = 0; i < item.children.length; i++) { | ||
| var found = findList(item.children[i]) | ||
| if (found) return found | ||
| } | ||
| return null | ||
| } | ||
|
|
||
| function rowIndex(itemId) { | ||
| for (var i = 0; i < list.model.count; i++) | ||
| if (list.model.get(i).itemId === itemId) return i | ||
| return -1 | ||
| } | ||
|
|
||
| function selectedId() { | ||
| return root.menu.cursorActive ? root.list.model.get(root.menu.selectedIndex).itemId : "" | ||
| } | ||
|
|
||
| Component.onCompleted: { | ||
| var component = Qt.createComponent(Quickshell.env("OMARCHY_PATH") + "/shell/plugins/menu/Menu.qml", Component.PreferSynchronous) | ||
| menu = component.createObject(root) | ||
| if (!menu) finish("Menu.qml failed to load: " + component.errorString()) | ||
| } | ||
|
|
||
| Timer { | ||
| interval: 100 | ||
| repeat: true | ||
| running: true | ||
| onTriggered: { | ||
| if (++root.waited > 100) { running = false; return root.finish("the menu never settled at stage " + root.stage) } | ||
| if (!root.menu || !root.menu.rowsLoaded) return | ||
|
|
||
| if (root.stage === "open") { | ||
| root.stage = "entered" | ||
| return root.menu.open("{}") | ||
| } | ||
| if (root.menu.guardsPending) return | ||
| // The rows live in the menu's own window. | ||
| for (var i = 0; i < root.menu.data.length && !root.list; i++) | ||
| if (root.menu.data[i].contentItem) root.list = root.findList(root.menu.data[i].contentItem) | ||
| if (!root.list) return | ||
|
|
||
| if (root.stage === "entered") { | ||
| var appearance = root.rowIndex("appearance") | ||
| if (appearance <= 0) return | ||
| root.menu.cursorActive = true | ||
| root.menu.selectedIndex = appearance | ||
| root.menu.activateIndex(appearance) | ||
| if (root.menu.activeMenu !== "appearance") { running = false; return root.finish("entering Appearance opened " + root.menu.activeMenu) } | ||
| root.menu.goBack() | ||
| if (root.selectedId() !== "appearance") { running = false; return root.finish("back from an entered Appearance lands on " + root.selectedId() + ", not Appearance") } | ||
| root.stage = "summoned" | ||
| return root.menu.open(JSON.stringify({ menu: "appearance" })) | ||
| } | ||
|
|
||
| running = false | ||
| if (root.menu.activeMenu !== "appearance") return root.finish("summoning Appearance opened " + root.menu.activeMenu) | ||
| root.menu.goBack() | ||
| if (root.selectedId() !== "appearance") return root.finish("back from a summoned Appearance lands on " + root.selectedId() + ", not Appearance") | ||
| root.finish("") | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests call only
nearestRowIndex; they never enter a submenu or callgoBack. Removing the newplaceCursorOncall would bring back the original bug while every added assertion still passed. Add a behavior test that enters a non-first row, goes back, and checks the selected row. Include a link whose row differs from its target to check the saved history frame too.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!