Skip to content

Commit

Permalink
bug fix that multi eventHandler does not fire (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengbomo authored May 18, 2024
1 parent 7422790 commit cfeff6b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions packages/hotkey_manager/lib/src/hotkey_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ class HotKeyManager {

if (keyEvent is KeyDownEvent) {
final physicalKeysPressed = HardwareKeyboard.instance.physicalKeysPressed;
HotKey? hotKey = _hotKeyList.firstWhereOrNull(
(e) {
List<HotKeyModifier> modifiers = HotKeyModifier.values
.where((e) => e.physicalKeys.any(physicalKeysPressed.contains))
.toList();
return e.scope == HotKeyScope.inapp &&
keyEvent.logicalKey == e.logicalKey &&
modifiers.length == (e.modifiers?.length ?? 0) &&
modifiers.every((e.modifiers ?? []).contains);
},
);
if (hotKey != null) {
HotKeyHandler? handler = _keyDownHandlerMap[hotKey.identifier];
if (handler != null) handler(hotKey);
_lastPressedHotKey = hotKey;
final hotKeys = _hotKeyList.where((e) {
List<HotKeyModifier> modifiers = HotKeyModifier.values
.where((e) => e.physicalKeys.any(physicalKeysPressed.contains))
.toList();
return e.scope == HotKeyScope.inapp &&
keyEvent.logicalKey == e.logicalKey &&
modifiers.length == (e.modifiers?.length ?? 0) &&
modifiers.every((e.modifiers ?? []).contains);
});
if (hotKeys.isNotEmpty) {
for (final hotKey in hotKeys) {
HotKeyHandler? handler = _keyDownHandlerMap[hotKey.identifier];
if (handler != null) handler(hotKey);
}
_lastPressedHotKey = hotKeys.last;
return true;
}
}
Expand Down

0 comments on commit cfeff6b

Please sign in to comment.