Repository navigation
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. |
|
|
@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>
|
Are we sure the behavior introduced in this PR is correct?
|
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.