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 121 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
@Tanya-Solyanik Tanya-Solyanik added the waiting-author-feedback The team requires more information from the author label May 7, 2025
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
Contributor

@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
Contributor

@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
Contributor

@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))

@LeafShi1 LeafShi1 requested a review from KlausLoeffelmann May 21, 2025 01:06
@Epica3055 Epica3055 added the waiting-review This item is waiting on review by one or more members of team label Jun 10, 2025
@LeafShi1
Copy link
Member

LeafShi1 commented Jun 16, 2025

LGTM! To avoid causing other regressions, a test is needed here.

@LeafShi1 LeafShi1 added the priority-1 Work that is critical for the release, but we could probably ship without label Jun 27, 2025
@KlausLoeffelmann
Copy link
Member

I have slightly stomach aches with this, but I cannot put my finger on it.
Can you test if this would affect

a) A hosted Control (TextBox, ComboBox, UserControl with other controls) inside of a ToolStrip?
b) A TextBox/ComboBox in a overflow menu?

Thanks!

@Epica3055
Copy link
Member Author

Epica3055 commented Jul 2, 2025

It seems fine. 🙂
@KlausLoeffelmann
13420_01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-StripControls priority-1 Work that is critical for the release, but we could probably ship without waiting-review This item is waiting on review by one or more members of team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot enter characters when adding ToolStripMenuItem1 and then adding ToolStripMenuItem2 after pressing enter in DemoConsole application
5 participants