MacOS: Do not send key event if modifiers flags haven't changed (flutter/engine#26347)

* MacOS: Do not send key event if modifiers flags haven't changed

Fixes https://github.com/flutter/flutter/issues/77535

* Extend unit test

* Comment typo
This commit is contained in:
Matej Knopp 2021-05-23 23:51:42 +02:00 committed by GitHub
parent 7bb9bed259
commit 46516e5327
2 changed files with 15 additions and 1 deletions

View File

@ -50,8 +50,12 @@
case NSEventTypeFlagsChanged:
if (event.modifierFlags < _previouslyPressedFlags) {
type = @"keyup";
} else {
} else if (event.modifierFlags > _previouslyPressedFlags) {
type = @"keydown";
} else {
// ignore duplicate modifiers; This can happen in situations like switching
// between application windows when MacOS only sends the up event to new window.
return;
}
break;
default:

View File

@ -170,6 +170,16 @@ TEST(FlutterChannelKeyResponderUnittests, BasicKeyEvent) {
[messages removeAllObjects];
[responses removeAllObjects];
// RShift up again, should be ignored and not produce a keydown event.
next_response = false;
[responder handleEvent:keyEvent(NSEventTypeFlagsChanged, 0x100, @"", @"", FALSE, 60)
callback:^(BOOL handled) {
[responses addObject:@(handled)];
}];
EXPECT_EQ([messages count], 0u);
EXPECT_EQ([responses count], 0u);
}
TEST(FlutterChannelKeyResponderUnittests, EmptyResponseIsTakenAsHandled) {