Skip to content

[V3] Restore hidden menuitem at correct position #4246

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

Conversation

superDingda
Copy link
Contributor

@superDingda superDingda commented Apr 27, 2025

Description

Currently, when a menuitem is hidden and then shown again, it is not restored to its correct original position.
This issue becomes worse when multiple items are hidden, as the relative ordering becomes completely incorrect.

Instead of using a stale itemAfter pointer, this patch dynamically recalculates the menuitem's correct position based on the current m.parent.items slice at the time of reinsertion.

Fixes #4236

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • New Features

    • Added a "Request Coffee" menu item in the demo menu, including options to enable/disable and show/hide the coffee request feature.
  • Documentation

    • Updated the changelog entry for improved clarity and contributor attribution regarding a previous fix.
  • Refactor

    • Simplified the logic for hiding and showing menu items on Windows, improving menu item visibility handling.

Copy link
Contributor

coderabbitai bot commented Apr 27, 2025

Walkthrough

This pull request updates the changelog to clarify and attribute a previous fix, enhances the menu example by adding new interactive menu items for requesting coffee and toggling their state and visibility, and refactors the internal logic for hiding and showing menu items on Windows. The refactor removes the itemAfter field from windowsMenuItem and changes how hidden menu items are restored, ensuring they reappear in the correct position by dynamically calculating their insertion index among visible siblings.

Changes

File(s) Change Summary
docs/src/content/docs/changelog.mdx Updated the changelog entry for the fallbackResponseWriter fix to improve clarity, add explicit contributor attribution, and reference the related issue.
v3/examples/menu/main.go Added new "Request Coffee" menu item and controls to toggle its enabled state and visibility, with associated handlers and UI updates.
v3/pkg/application/menuitem_windows.go Removed itemAfter field from windowsMenuItem and refactored the logic for hiding/showing menu items to restore them in the correct position by counting visible siblings.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Menu
    participant MenuItem

    User->>Menu: Clicks "Hide the coffee option"
    Menu->>MenuItem: setHidden(true)
    MenuItem-->>Menu: Updates visibility

    User->>Menu: Clicks "Unhide the coffee option"
    Menu->>MenuItem: setHidden(false)
    MenuItem->>Menu: Calculates correct position among visible items
    MenuItem-->>Menu: Re-inserts at correct position
Loading

Assessment against linked issues

Objective Addressed Explanation
Hiding and then showing a menuitem restores it in the wrong position (#4236)

Possibly related PRs

Suggested labels

awaiting feedback

Suggested reviewers

  • leaanthony

Poem

In the menu’s warren, a coffee hop appears,
With toggles and tricks for the barista’s cheers.
Hide and unhide, each item in line,
Now restored in its place, oh how divine!
The changelog gives thanks, the code hops anew—
A rabbit’s delight in what menus can do!
☕🐇


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2bfbe7f and c922a7e.

📒 Files selected for processing (3)
  • docs/src/content/docs/changelog.mdx (1 hunks)
  • v3/examples/menu/main.go (1 hunks)
  • v3/pkg/application/menuitem_windows.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
v3/pkg/application/menuitem_windows.go (3)
v3/pkg/w32/typedef.go (1)
  • HMENU (210-210)
v3/pkg/w32/popupmenu.go (1)
  • RemoveMenu (27-33)
v3/pkg/w32/constants.go (1)
  • MF_BYCOMMAND (3454-3454)
🪛 LanguageTool
docs/src/content/docs/changelog.mdx

[style] ~127-~127: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...m/leaanthony) based on work by @Kron. - Fixed fallbackResponseWriter not implementing...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🔇 Additional comments (4)
docs/src/content/docs/changelog.mdx (1)

127-128: Improved attribution for fix in changelog.

The fix is now properly attributed to the contributor (@superDingda) with a clear link to the related issue (#4236). This follows good open-source practice of crediting contributors.

🧰 Tools
🪛 LanguageTool

[style] ~127-~127: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...m/leaanthony) based on work by @Kron. - Fixed fallbackResponseWriter not implementing...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

v3/pkg/application/menuitem_windows.go (2)

11-23: Removed itemAfter field to improve menu item management.

The removal of the itemAfter field from the windowsMenuItem struct simplifies the state management by eliminating a potential source of stale references.


32-41: More robust approach to restoring hidden menu items.

The new implementation dynamically calculates the correct insertion position based on the current state of visible siblings, instead of relying on a potentially stale reference. This ensures menu items are restored at the proper position regardless of other menu changes that may have occurred while the item was hidden.

v3/examples/menu/main.go (1)

117-146: Good demonstration of menu item visibility and state management.

The new coffee-themed menu items effectively demonstrate the menu functionality for:

  1. Toggling menu item visibility (hide/unhide)
  2. Changing enabled state and labels
  3. Handling user interaction through callbacks

This example provides a clear demonstration of how the improved menu item reinsertion logic works in practice, ensuring items reappear in their correct positions.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@superDingda superDingda changed the title fix: restore hidden menuitem at correct position [V3] restore hidden menuitem at correct position Apr 27, 2025
@superDingda superDingda changed the title [V3] restore hidden menuitem at correct position [V3] Restore hidden menuitem at correct position Apr 27, 2025
@leaanthony
Copy link
Member

You legend! This was on my blockers list 🚀

@leaanthony leaanthony merged commit 191ce6b into wailsapp:v3-alpha Apr 28, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants