-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: main
Are you sure you want to change the base?
Conversation
…m1 and then adding ToolStripMenuItem2 after pressing enter in DemoConsole application
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs
Outdated
Show resolved
Hide resolved
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.
Other than a small comment, LGTM!
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.
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)
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs
Outdated
Show resolved
Hide resolved
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.
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.
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs
Show resolved
Hide resolved
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.
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))
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs
Show resolved
Hide resolved
LGTM! To avoid causing other regressions, a test is needed here. |
I have slightly stomach aches with this, but I cannot put my finger on it. a) A hosted Control (TextBox, ComboBox, UserControl with other controls) inside of a ToolStrip? Thanks! |
It seems fine. 🙂 |
Fixes #13400
Proposed changes
This issue is introduced by pull/13034, this is the change made by it.
In my debugging, I found that
ToolStripManager.ModalMenuFilter.SetActiveToolStrip(this);
got invoked too many times evenToolStrip
didn't lost focus, which I think caused the issue.So I exclude some cases.
Screenshots
Before
cannot.input.mp4
After
Test methodology