fix(controls): Stop HotKeyManager from triggering on hidden controls (#21708) - #21714
Conversation
db8a79a to
3b4b09a
Compare
|
You can test this PR using the following package version. |
|
@1419323749, Please read the following Contributor License Agreement (CLA). If you agree with the CLA, please reply with the following: Contributor License AgreementContribution License AgreementThis Contribution License Agreement ( âAgreementâ ) is agreed to by the party signing below ( âYouâ ), 1. Definitions. âCodeâ means the computer software code, whether in human-readable or machine-executable form, âProjectâ means any of the projects owned or managed by AvaloniaUI OÃ and offered under a license âSubmitâ is the act of uploading, submitting, transmitting, or distributing code or other content to any âSubmissionâ means the Code and any other copyrightable material Submitted by You, including any 2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any 3. Originality of Work. You represent that each of Your Submissions is entirely Your 4. Your Employer. References to âemployerâ in this Agreement include Your employer or anyone else 5. Licenses. a. Copyright License. You grant AvaloniaUI OÃ, and those who receive the Submission directly b. Patent License. You grant AvaloniaUI OÃ, and those who receive the Submission directly or c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. 6. Representations and Warranties. You represent that You are legally entitled to grant the above 7. Notice to AvaloniaUI OÃ. You agree to notify AvaloniaUI OÃ in writing of any facts or 8. Information about Submissions. You agree that contributions to Projects and information about 9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the Republic of Estonia, and 10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and AvaloniaUI OÃ dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1. 1 out of 2 committers have signed the CLA.
|
|
@cla-avalonia agree
æūčŋ
***@***.***
|
|
You can test this PR using the following package version. |
| while (current != null && current is not TopLevel) | ||
| { | ||
| if (!current.IsVisible) | ||
| { | ||
| return false; | ||
| } | ||
| current = current.VisualParent; | ||
| } |
There was a problem hiding this comment.
Would inputElement.IsEffectivelyVisible be sufficient?
There was a problem hiding this comment.
I initially switched to IsEffectivelyVisible as suggested, but it turns out its
semantics include the TopLevel's own IsVisible in the ancestor chain. This broke
several existing unit tests where the test Window is constructed via ApplyTemplate()
without calling Show() (so Window.IsVisible defaults to false).
I think the original manual traversal (stopping before checking the TopLevel itself)
is actually more correct here â we want to detect a hidden container inside an
already-shown window, not conflate that with whether the window itself has been shown.
I've restored that approach, let me know if you'd prefer a different way to handle this.
7360cf9 to
f6e549d
Compare
- Added a check for 'target.IsEffectivelyVisible' inside 'HotkeyCommandWrapper.CanExecute'. - Prevents HotKey from globally triggering and swallowing keyboard input when the host control or its parent panels are invisible (IsVisible="False"). - Added a corresponding unit test to verify input routing for hidden clickable controls. Closes AvaloniaUI#21708
f6e549d to
9638683
Compare
|
You can test this PR using the following package version. |
|
You can test this PR using the following package version. |
âĶ21714) - Added a check for 'target.IsEffectivelyVisible' inside 'HotkeyCommandWrapper.CanExecute'. - Prevents HotKey from globally triggering and swallowing keyboard input when the host control or its parent panels are invisible (IsVisible="False"). - Added a corresponding unit test to verify input routing for hidden clickable controls. Closes #21708 Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
Description
This PR fixes a global input-swallowing bug where
HotKeyManagerremains active and continues to intercept keyboard input even when the associated host control (or any of its parent layout containers) has been hidden viaIsVisible="False".Cause of the Bug
The
HotkeyCommandWrapper.CanExecutemethod previously only checked forIsEffectivelyEnabled. However, when a control or its parent is hidden,IsEffectivelyEnabledoften remainstrue. As a result, when the global shortcut key is pressed, the wrapper incorrectly approves execution, invokes the action, and setsargs.Handled = true, effectively stealing the keyboard input from other visible parts of the application.Solution
HotkeyCommandWrapper.CanExecuteto securely cast the target toControl.if (!target.IsEffectivelyVisible) return false;. This ensures that shortcuts on invisible controls are gracefully ignored, letting the key event route freely to other focused elements.Related Issues
Closes #21708
Type of Change
Checklist
dotnet formathas been executed).Avalonia.Controls.UnitTeststhat proves my fix is effective.