Skip to content

Commit

Permalink
UI/AppKit: Only check the NSEvent isARepeat flag in key down/up events
Browse files Browse the repository at this point in the history
We call ns_event_to_key_event for the NSFlagsChanged event as well. By
retrieving the isARepeat flag on those events, we are guaranteed to
throw an exception.

See:
https://developer.apple.com/documentation/appkit/nsevent/1528049-arepeat?language=objc

    Raises an NSInternalInconsistencyException if sent to an
    NSFlagsChanged event or other non-key event.
  • Loading branch information
trflynn89 committed Oct 24, 2024
1 parent 00c4524 commit d2d861c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Ladybird/AppKit/UI/Event.mm
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ explicit KeyData(NSEvent* event)
{
auto modifiers = ns_modifiers_to_key_modifiers(event.modifierFlags);
auto key_code = ns_key_code_to_key_code(event.keyCode, modifiers);
auto repeat = event.isARepeat;
auto repeat = false;

// FIXME: WebContent should really support multi-code point key events.
u32 code_point = 0;
Expand All @@ -307,6 +307,8 @@ explicit KeyData(NSEvent* event)
Utf8View utf8_view { StringView { utf8, strlen(utf8) } };

code_point = utf8_view.is_empty() ? 0u : *utf8_view.begin();

repeat = event.isARepeat;
}

// NSEvent assigns PUA code points to to functional keys, e.g. arrow keys. Do not propagate them.
Expand Down

0 comments on commit d2d861c

Please sign in to comment.