Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7f4f62d

Browse files
committed
Do not generate keydown event for empty modifier flags
1 parent 77e67df commit 7f4f62d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ - (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
5050
case NSEventTypeFlagsChanged:
5151
if (event.modifierFlags < _previouslyPressedFlags) {
5252
type = @"keyup";
53-
} else if (event.modifierFlags > _previouslyPressedFlags) {
53+
} else if (event.modifierFlags > _previouslyPressedFlags &&
54+
event.modifierFlags > 0x100) { // 0x100 is empty modifierFlags
5455
type = @"keydown";
5556
} else {
5657
// ignore duplicate modifiers; This can happen in situations like switching

shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponderUnittests.mm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,18 @@
5252
callback(keyMessage);
5353
}));
5454

55-
// Key down
5655
FlutterChannelKeyResponder* responder =
5756
[[FlutterChannelKeyResponder alloc] initWithChannel:mockKeyEventChannel];
57+
58+
// Empty modifiers. Shouldn't result in any event
59+
[responder handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, 60)
60+
callback:^(BOOL handled) {
61+
[responses addObject:@(handled)];
62+
}];
63+
64+
EXPECT_EQ([messages count], 0u);
65+
66+
// Key down
5867
[responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x100, @"a", @"a", FALSE, 0)
5968
callback:^(BOOL handled) {
6069
[responses addObject:@(handled)];

0 commit comments

Comments
 (0)