Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix #13400 Cannot enter characters when adding ToolStripMenuItem1 and then adding ToolStripMenuItem2 after pressing enter in DemoConsole application #13420

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
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Epica3055
Copy link
Member

@Epica3055 Epica3055 commented May 7, 2025

Fixes #13400

Proposed changes

This issue is introduced by pull/13034, this is the change made by it.

    protected override void WndProc(ref Message m)
    {
        if (m.MsgInternal == PInvokeCore.WM_SETFOCUS)
        {
            SnapFocus((HWND)(nint)m.WParamInternal);

+            // For fix https://github.com/dotnet/winforms/issues/12916
+           ToolStripManager.ModalMenuFilter.SetActiveToolStrip(this);
        }
  ....

In my debugging, I found that ToolStripManager.ModalMenuFilter.SetActiveToolStrip(this); got invoked too many times even ToolStrip didn't lost focus, which I think caused the issue.

So I exclude some cases.

Screenshots

Before

cannot.input.mp4

After

Issue_13400_02
Issue_13400_03

Test methodology

  • manual

…m1 and then adding ToolStripMenuItem2 after pressing enter in DemoConsole application
Copy link

codecov bot commented May 7, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.

Project coverage is 76.59942%. Comparing base (71a8e95) to head (6382336).
Report is 3 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #13420         +/-   ##
===================================================
- Coverage   76.60371%   76.59942%   -0.00430%     
===================================================
  Files           3230        3230                 
  Lines         639097      639108         +11     
  Branches       47289       47291          +2     
===================================================
- Hits          489572      489553         -19     
- Misses        145953      145980         +27     
- Partials        3572        3575          +3     
Flag Coverage Δ
Debug 76.59942% <66.66667%> (-0.00430%) ⬇️
integration 18.78841% <66.66667%> (+0.00032%) ⬆️
production 51.00244% <66.66667%> (-0.00859%) ⬇️
test 97.40411% <ø> (ø)
unit 48.40883% <66.66667%> (-0.01024%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Epica3055 Epica3055 marked this pull request as ready for review May 7, 2025 06:19
@Epica3055 Epica3055 requested a review from a team as a code owner May 7, 2025 06:19

static bool IsOuterToolStrip(ToolStrip toolStrip)
{
static ToolStrip getParentToolStrip(ToolStrip toolStrip)
Copy link
Member

@Tanya-Solyanik Tanya-Solyanik May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Had you searched if we already have methods that do the same thing?
  • Enable nullability around this new code - Parent can not a toolstrip.
  • Please replace recursion with a while loop.
  • In general, while making changes, ask VS copilot chat to review your work. and make suggestions to improve the code.
  • Do we have a test case in the interactive test app, if not, please add one, create a new page if needed.
  • when creating a PR, please verify if labeler adds a correct label and if the one it adds if needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had you searched if we already have methods that do the same thing?

We have one similar method, but it doesn't satisfy me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test case in the interactive test app, if not, please add one, create a new page if needed.

This issue happens in DemoConsole. if we need to add a test case in the interactive test app, then I think we will need to build up a Desginer Environment like DemoConsole.

@Tanya-Solyanik Tanya-Solyanik added the waiting-author-feedback The team requires more information from the author label May 7, 2025

static bool IsOuterToolStrip(ToolStrip toolStrip)
{
static ToolStrip getParentToolStrip(ToolStrip toolStrip)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Methods should be PastelCase

Copy link
Member

@ricardobossan ricardobossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than a small comment, LGTM!

@dotnet-policy-service dotnet-policy-service bot removed the waiting-author-feedback The team requires more information from the author label May 8, 2025
@Epica3055 Epica3055 requested a review from Copilot May 8, 2025 07:56
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issue #13400 by reducing unnecessary invocations of ToolStripManager.ModalMenuFilter.SetActiveToolStrip, which previously affected focus behavior in the DemoConsole application.

  • Added a condition to ensure SetActiveToolStrip is only called for outer (top-level) ToolStrips
  • Introduced a static local function IsOuterToolStrip to traverse the parent hierarchy
Comments suppressed due to low confidence (1)

src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs:4655

  • [nitpick] The method name 'IsOuterToolStrip' may be ambiguous; consider renaming it to 'IsRootToolStrip' to clearly indicate that it checks for a top-level ToolStrip.
static bool IsOuterToolStrip(ToolStrip toolStrip)

@Epica3055 Epica3055 requested a review from Copilot May 8, 2025 08:03
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issue #13400 by refining the logic in WndProc to prevent multiple invocations of SetActiveToolStrip when the ToolStrip does not lose focus.

  • Added a condition to only call SetActiveToolStrip if the current ToolStrip is an outer ToolStrip.
  • Introduced a local static helper method, IsOuterToolStrip, to determine if the ToolStrip is at the top of the hierarchy.

@Epica3055 Epica3055 requested a review from Copilot May 8, 2025 08:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes issue #13400 by restricting focus changes to only the outermost ToolStrip, preventing redundant invocations of ToolStripManager.ModalMenuFilter.SetActiveToolStrip.

  • Added a conditional check ("if (IsOuterToolStrip(this))") in WndProc to ensure the active ToolStrip is the outer one.
  • Introduced a local static helper function, IsOuterToolStrip, to navigate the parent hierarchy and determine the outer ToolStrip.
Comments suppressed due to low confidence (1)

src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs:4586

  • Include unit tests for scenarios with nested ToolStrips to ensure that the outer ToolStrip is correctly identified and activated.
if (IsOuterToolStrip(this))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants