fix: use path-based menuId to prevent collisions in nested submenus#3762
Open
chrism wants to merge 1 commit intosoftware-mansion:mainfrom
Open
fix: use path-based menuId to prevent collisions in nested submenus#3762chrism wants to merge 1 commit intosoftware-mansion:mainfrom
chrism wants to merge 1 commit intosoftware-mansion:mainfrom
Conversation
When prepareMenu recurses into submenus, it passes menuIndex as the
index parameter instead of preserving the original bar button item
index. This causes menuId collisions between actions in different
submenus and sibling toolbar menus that share the same position.
For example, with two toolbar menu buttons (filter at index 1, sort
at index 2), a submenu item at menuIndex 2 inside the filter menu
generates menuId "0-2-right", which collides with the first action
in the sort menu ("0-2-right"). This causes menu action callbacks
to fire on the wrong handler.
Fix by threading a path string through recursion that tracks the
nesting position (e.g. "2.0" for the first item in the third
submenu), while preserving the original bar button item index.
This produces unique menuIds like "2.0-1-right" that never collide
with sibling menus.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
prepareMenupassesmenuIndexasindexwhen recursing into submenus, losing the original bar button item indexmenuIdcollisions between actions in different submenus and sibling toolbar menus at the same positionpathstring through recursion to track nesting depth, while preserving the original bar button item indexProblem
Given two toolbar menu buttons — a filter menu at bar button index 1 containing submenus, and a sort menu at bar button index 2:
When
prepareMenurecurses into the Quality submenu (atmenuIndex2 inside the filter menu), it calls:The first action inside Quality then gets
menuId: "0-2-right", which collides with the first action in the sort menu ("0-2-right"). Selecting a quality filter fires the sort handler instead.Fix
Add a
pathparameter that tracks position through nesting, while keeping the original bar buttonindex:Before: Quality "All" =
0-2-right(collides with Sort "Title" =0-2-right)After: Quality "All" =
2.0-1-right, Sort "Title" =0-2-right(unique)Verified