Skip to content

Commit

Permalink
Do not generate keydown event for empty modifier flags
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp committed Jul 30, 2021
1 parent 72c8e55 commit 1197c82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ - (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
case NSEventTypeFlagsChanged:
if (event.modifierFlags < _previouslyPressedFlags) {
type = @"keyup";
} else if (event.modifierFlags > _previouslyPressedFlags) {
} else if (event.modifierFlags > _previouslyPressedFlags &&
event.modifierFlags > 0x100) { // 0x100 is empty modifierFlags
type = @"keydown";
} else {
// ignore duplicate modifiers; This can happen in situations like switching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,18 @@
callback(keyMessage);
}));

// Key down
FlutterChannelKeyResponder* responder =
[[FlutterChannelKeyResponder alloc] initWithChannel:mockKeyEventChannel];

// Empty modifiers. Shouldn't result in any event
[responder handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, 60)
callback:^(BOOL handled) {
[responses addObject:@(handled)];
}];

EXPECT_EQ([messages count], 0u);

// Key down
[responder handleEvent:keyEvent(NSEventTypeKeyDown, 0x100, @"a", @"a", FALSE, 0)
callback:^(BOOL handled) {
[responses addObject:@(handled)];
Expand Down

0 comments on commit 1197c82

Please sign in to comment.