Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not generate keydown event for empty modifier flags #27817

Merged
merged 6 commits into from
Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ - (nonnull instancetype)initWithChannel:(nonnull FlutterBasicMessageChannel*)cha
}

- (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
// Remove the modifier bits that Flutter is not interested in.
NSEventModifierFlags modifierFlags = event.modifierFlags & ~0x100;
NSString* type;
switch (event.type) {
case NSEventTypeKeyDown:
Expand All @@ -48,9 +50,9 @@ - (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
type = @"keyup";
break;
case NSEventTypeFlagsChanged:
if (event.modifierFlags < _previouslyPressedFlags) {
if (modifierFlags < _previouslyPressedFlags) {
type = @"keyup";
} else if (event.modifierFlags > _previouslyPressedFlags) {
} else if (modifierFlags > _previouslyPressedFlags) {
type = @"keydown";
} else {
// ignore duplicate modifiers; This can happen in situations like switching
Expand All @@ -61,7 +63,7 @@ - (void)handleEvent:(NSEvent*)event callback:(FlutterAsyncKeyCallback)callback {
default:
NSAssert(false, @"Unexpected key event type (got %lu).", event.type);
}
_previouslyPressedFlags = event.modifierFlags;
_previouslyPressedFlags = modifierFlags;
NSMutableDictionary* keyMessage = [@{
@"keymap" : @"macos",
@"type" : type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@
callback(keyMessage);
}));

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

// Initial empty modifiers. This can happen when user opens window while modifier key is pressed
// and then releases the modifier. Shouldn't result in an event being sent.
knopp marked this conversation as resolved.
Show resolved Hide resolved
// Regression test for https://github.com/flutter/flutter/issues/87339.
[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